home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / webkit / resources.pak / Unnamed File 000112.unknown < prev    next >
Text File  |  2013-04-03  |  1MB  |  50,429 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6. Object.isEmpty = function(obj)
  7. {
  8. for (var i in obj)
  9. return false;
  10. return true;
  11. }
  12.  
  13. Object.values = function(obj)
  14. {
  15. var keys = Object.keys(obj);
  16. var result = [];
  17.  
  18. for (var i = 0; i < keys.length; ++i)
  19. result.push(obj[keys[i]]);
  20. return result;
  21. }
  22.  
  23. String.prototype.hasSubstring = function(string, caseInsensitive)
  24. {
  25. if (!caseInsensitive)
  26. return this.indexOf(string) !== -1;
  27. return this.match(new RegExp(string.escapeForRegExp(), "i"));
  28. }
  29.  
  30. String.prototype.findAll = function(string)
  31. {
  32. var matches = [];
  33. var i = this.indexOf(string);
  34. while (i !== -1) {
  35. matches.push(i);
  36. i = this.indexOf(string, i + string.length);
  37. }
  38. return matches;
  39. }
  40.  
  41. String.prototype.lineEndings = function()
  42. {
  43. if (!this._lineEndings) {
  44. this._lineEndings = this.findAll("\n");
  45. this._lineEndings.push(this.length);
  46. }
  47. return this._lineEndings;
  48. }
  49.  
  50. String.prototype.escapeCharacters = function(chars)
  51. {
  52. var foundChar = false;
  53. for (var i = 0; i < chars.length; ++i) {
  54. if (this.indexOf(chars.charAt(i)) !== -1) {
  55. foundChar = true;
  56. break;
  57. }
  58. }
  59.  
  60. if (!foundChar)
  61. return this;
  62.  
  63. var result = "";
  64. for (var i = 0; i < this.length; ++i) {
  65. if (chars.indexOf(this.charAt(i)) !== -1)
  66. result += "\\";
  67. result += this.charAt(i);
  68. }
  69.  
  70. return result;
  71. }
  72.  
  73. String.prototype.escapeForRegExp = function()
  74. {
  75. return this.escapeCharacters("^[]{}()\\.$*+?|");
  76. }
  77.  
  78. String.prototype.escapeHTML = function()
  79. {
  80. return this.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """); 
  81. }
  82.  
  83. String.prototype.collapseWhitespace = function()
  84. {
  85. return this.replace(/[\s\xA0]+/g, " ");
  86. }
  87.  
  88. String.prototype.trimMiddle = function(maxLength)
  89. {
  90. if (this.length <= maxLength)
  91. return this;
  92. var leftHalf = maxLength >> 1;
  93. var rightHalf = maxLength - leftHalf - 1;
  94. return this.substr(0, leftHalf) + "\u2026" + this.substr(this.length - rightHalf, rightHalf);
  95. }
  96.  
  97. String.prototype.trimEnd = function(maxLength)
  98. {
  99. if (this.length <= maxLength)
  100. return this;
  101. return this.substr(0, maxLength - 1) + "\u2026";
  102. }
  103.  
  104. String.prototype.trimURL = function(baseURLDomain)
  105. {
  106. var result = this.replace(/^(https|http|file):\/\//i, "");
  107. if (baseURLDomain)
  108. result = result.replace(new RegExp("^" + baseURLDomain.escapeForRegExp(), "i"), "");
  109. return result;
  110. }
  111.  
  112.  
  113. function sanitizeHref(href)
  114. {
  115. return href && href.trim().toLowerCase().startsWith("javascript:") ? "" : href;
  116. }
  117.  
  118. String.prototype.removeURLFragment = function()
  119. {
  120. var fragmentIndex = this.indexOf("#");
  121. if (fragmentIndex == -1)
  122. fragmentIndex = this.length;
  123. return this.substring(0, fragmentIndex);
  124. }
  125.  
  126. String.prototype.startsWith = function(substring)
  127. {
  128. return !this.lastIndexOf(substring, 0);
  129. }
  130.  
  131. String.prototype.endsWith = function(substring)
  132. {
  133. return this.indexOf(substring, this.length - substring.length) !== -1;
  134. }
  135.  
  136. Number.constrain = function(num, min, max)
  137. {
  138. if (num < min)
  139. num = min;
  140. else if (num > max)
  141. num = max;
  142. return num;
  143. }
  144.  
  145. Date.prototype.toISO8601Compact = function()
  146. {
  147. function leadZero(x)
  148. {
  149. return x > 9 ? '' + x : '0' + x
  150. }
  151. return this.getFullYear() +
  152. leadZero(this.getMonth() + 1) +
  153. leadZero(this.getDate()) + 'T' +
  154. leadZero(this.getHours()) +
  155. leadZero(this.getMinutes()) +
  156. leadZero(this.getSeconds());
  157. }
  158.  
  159. Object.defineProperty(Array.prototype, "remove",
  160. {
  161.  
  162. value: function(value, onlyFirst)
  163. {
  164. if (onlyFirst) {
  165. var index = this.indexOf(value);
  166. if (index !== -1)
  167. this.splice(index, 1);
  168. return;
  169. }
  170.  
  171. var length = this.length;
  172. for (var i = 0; i < length; ++i) {
  173. if (this[i] === value)
  174. this.splice(i, 1);
  175. }
  176. }
  177. });
  178.  
  179. Object.defineProperty(Array.prototype, "keySet",
  180. {
  181.  
  182. value: function()
  183. {
  184. var keys = {};
  185. for (var i = 0; i < this.length; ++i)
  186. keys[this[i]] = true;
  187. return keys;
  188. }
  189. });
  190.  
  191. Object.defineProperty(Array.prototype, "upperBound",
  192. {
  193.  
  194. value: function(value)
  195. {
  196. var first = 0;
  197. var count = this.length;
  198. while (count > 0) {
  199. var step = count >> 1;
  200. var middle = first + step;
  201. if (value >= this[middle]) {
  202. first = middle + 1;
  203. count -= step + 1;
  204. } else
  205. count = step;
  206. }
  207. return first;
  208. }
  209. });
  210.  
  211. Object.defineProperty(Array.prototype, "rotate",
  212. {
  213.  
  214. value: function(index)
  215. {
  216. var result = [];
  217. for (var i = index; i < index + this.length; ++i)
  218. result.push(this[i % this.length]);
  219. return result;
  220. }
  221. });
  222.  
  223. Object.defineProperty(Uint32Array.prototype, "sort", {
  224. value: Array.prototype.sort
  225. });
  226.  
  227. (function() {
  228. var partition = {
  229.  
  230. value: function(comparator, left, right, pivotIndex)
  231. {
  232. function swap(array, i1, i2)
  233. {
  234. var temp = array[i1];
  235. array[i1] = array[i2];
  236. array[i2] = temp;
  237. }
  238.  
  239. var pivotValue = this[pivotIndex];
  240. swap(this, right, pivotIndex);
  241. var storeIndex = left;
  242. for (var i = left; i < right; ++i) {
  243. if (comparator(this[i], pivotValue) < 0) {
  244. swap(this, storeIndex, i);
  245. ++storeIndex;
  246. }
  247. }
  248. swap(this, right, storeIndex);
  249. return storeIndex;
  250. }
  251. };
  252. Object.defineProperty(Array.prototype, "partition", partition);
  253. Object.defineProperty(Uint32Array.prototype, "partition", partition);
  254.  
  255. var sortRange = {
  256.  
  257. value: function(comparator, leftBound, rightBound, k)
  258. {
  259. function quickSortFirstK(array, comparator, left, right, k)
  260. {
  261. if (right <= left)
  262. return;
  263. var pivotIndex = Math.floor(Math.random() * (right - left)) + left;
  264. var pivotNewIndex = array.partition(comparator, left, right, pivotIndex);
  265. quickSortFirstK(array, comparator, left, pivotNewIndex - 1, k);
  266. if (pivotNewIndex < left + k - 1)
  267. quickSortFirstK(array, comparator, pivotNewIndex + 1, right, k);
  268. }
  269.  
  270. if (leftBound === 0 && rightBound === (this.length - 1) && k === this.length)
  271. this.sort(comparator);
  272. else
  273. quickSortFirstK(this, comparator, leftBound, rightBound, k);
  274. return this;
  275. }
  276. }
  277. Object.defineProperty(Array.prototype, "sortRange", sortRange);
  278. Object.defineProperty(Uint32Array.prototype, "sortRange", sortRange);
  279. })();
  280.  
  281. Object.defineProperty(Array.prototype, "qselect",
  282. {
  283.  
  284. value: function(k, comparator)
  285. {
  286. if (k < 0 || k >= this.length)
  287. return;
  288. if (!comparator)
  289. comparator = function(a, b) { return a - b; }
  290.  
  291. var low = 0;
  292. var high = this.length - 1;
  293. for (;;) {
  294. var pivotPosition = this.partition(comparator, low, high, Math.floor((high + low) / 2));
  295. if (pivotPosition === k)
  296. return this[k];
  297. else if (pivotPosition > k)
  298. high = pivotPosition - 1;
  299. else
  300. low = pivotPosition + 1;
  301. }
  302. }
  303. });
  304.  
  305.  
  306. function binarySearch(object, array, comparator)
  307. {
  308. var first = 0;
  309. var last = array.length - 1;
  310.  
  311. while (first <= last) {
  312. var mid = (first + last) >> 1;
  313. var c = comparator(object, array[mid]);
  314. if (c > 0)
  315. first = mid + 1;
  316. else if (c < 0)
  317. last = mid - 1;
  318. else
  319. return mid;
  320. }
  321.  
  322.  
  323. return -(first + 1);
  324. }
  325.  
  326. Object.defineProperty(Array.prototype, "binaryIndexOf",
  327. {
  328.  
  329. value: function(value, comparator)
  330. {
  331. var result = binarySearch(value, this, comparator);
  332. return result >= 0 ? result : -1;
  333. }
  334. });
  335.  
  336. Object.defineProperty(Array.prototype, "select",
  337. {
  338.  
  339. value: function(field)
  340. {
  341. var result = new Array(this.length);
  342. for (var i = 0; i < this.length; ++i)
  343. result[i] = this[i][field];
  344. return result;
  345. }
  346. });
  347.  
  348.  
  349. function insertionIndexForObjectInListSortedByFunction(anObject, aList, aFunction)
  350. {
  351. var index = binarySearch(anObject, aList, aFunction);
  352. if (index < 0)
  353.  
  354. return -index - 1;
  355. else {
  356.  
  357. while (index > 0 && aFunction(anObject, aList[index - 1]) === 0)
  358. index--;
  359. return index;
  360. }
  361. }
  362.  
  363.  
  364. String.sprintf = function(format, var_arg)
  365. {
  366. return String.vsprintf(format, Array.prototype.slice.call(arguments, 1));
  367. }
  368.  
  369. String.tokenizeFormatString = function(format, formatters)
  370. {
  371. var tokens = [];
  372. var substitutionIndex = 0;
  373.  
  374. function addStringToken(str)
  375. {
  376. tokens.push({ type: "string", value: str });
  377. }
  378.  
  379. function addSpecifierToken(specifier, precision, substitutionIndex)
  380. {
  381. tokens.push({ type: "specifier", specifier: specifier, precision: precision, substitutionIndex: substitutionIndex });
  382. }
  383.  
  384. function isDigit(c)
  385. {
  386. return !!/[0-9]/.exec(c);
  387. }
  388.  
  389. var index = 0;
  390. for (var precentIndex = format.indexOf("%", index); precentIndex !== -1; precentIndex = format.indexOf("%", index)) {
  391. addStringToken(format.substring(index, precentIndex));
  392. index = precentIndex + 1;
  393.  
  394. if (isDigit(format[index])) {
  395.  
  396. var number = parseInt(format.substring(index), 10);
  397. while (isDigit(format[index]))
  398. ++index;
  399.  
  400.  
  401.  
  402. if (number > 0 && format[index] === "$") {
  403. substitutionIndex = (number - 1);
  404. ++index;
  405. }
  406. }
  407.  
  408. var precision = -1;
  409. if (format[index] === ".") {
  410.  
  411.  
  412. ++index;
  413. precision = parseInt(format.substring(index), 10);
  414. if (isNaN(precision))
  415. precision = 0;
  416.  
  417. while (isDigit(format[index]))
  418. ++index;
  419. }
  420.  
  421. if (!(format[index] in formatters)) {
  422. addStringToken(format.substring(precentIndex, index + 1));
  423. ++index;
  424. continue;
  425. }
  426.  
  427. addSpecifierToken(format[index], precision, substitutionIndex);
  428.  
  429. ++substitutionIndex;
  430. ++index;
  431. }
  432.  
  433. addStringToken(format.substring(index));
  434.  
  435. return tokens;
  436. }
  437.  
  438. String.standardFormatters = {
  439. d: function(substitution)
  440. {
  441. return !isNaN(substitution) ? substitution : 0;
  442. },
  443.  
  444. f: function(substitution, token)
  445. {
  446. if (substitution && token.precision > -1)
  447. substitution = substitution.toFixed(token.precision);
  448. return !isNaN(substitution) ? substitution : (token.precision > -1 ? Number(0).toFixed(token.precision) : 0);
  449. },
  450.  
  451. s: function(substitution)
  452. {
  453. return substitution;
  454. }
  455. }
  456.  
  457. String.vsprintf = function(format, substitutions)
  458. {
  459. return String.format(format, substitutions, String.standardFormatters, "", function(a, b) { return a + b; }).formattedResult;
  460. }
  461.  
  462. String.format = function(format, substitutions, formatters, initialValue, append)
  463. {
  464. if (!format || !substitutions || !substitutions.length)
  465. return { formattedResult: append(initialValue, format), unusedSubstitutions: substitutions };
  466.  
  467. function prettyFunctionName()
  468. {
  469. return "String.format(\"" + format + "\", \"" + substitutions.join("\", \"") + "\")";
  470. }
  471.  
  472. function warn(msg)
  473. {
  474. console.warn(prettyFunctionName() + ": " + msg);
  475. }
  476.  
  477. function error(msg)
  478. {
  479. console.error(prettyFunctionName() + ": " + msg);
  480. }
  481.  
  482. var result = initialValue;
  483. var tokens = String.tokenizeFormatString(format, formatters);
  484. var usedSubstitutionIndexes = {};
  485.  
  486. for (var i = 0; i < tokens.length; ++i) {
  487. var token = tokens[i];
  488.  
  489. if (token.type === "string") {
  490. result = append(result, token.value);
  491. continue;
  492. }
  493.  
  494. if (token.type !== "specifier") {
  495. error("Unknown token type \"" + token.type + "\" found.");
  496. continue;
  497. }
  498.  
  499. if (token.substitutionIndex >= substitutions.length) {
  500.  
  501.  
  502. error("not enough substitution arguments. Had " + substitutions.length + " but needed " + (token.substitutionIndex + 1) + ", so substitution was skipped.");
  503. result = append(result, "%" + (token.precision > -1 ? token.precision : "") + token.specifier);
  504. continue;
  505. }
  506.  
  507. usedSubstitutionIndexes[token.substitutionIndex] = true;
  508.  
  509. if (!(token.specifier in formatters)) {
  510.  
  511. warn("unsupported format character \u201C" + token.specifier + "\u201D. Treating as a string.");
  512. result = append(result, substitutions[token.substitutionIndex]);
  513. continue;
  514. }
  515.  
  516. result = append(result, formatters[token.specifier](substitutions[token.substitutionIndex], token));
  517. }
  518.  
  519. var unusedSubstitutions = [];
  520. for (var i = 0; i < substitutions.length; ++i) {
  521. if (i in usedSubstitutionIndexes)
  522. continue;
  523. unusedSubstitutions.push(substitutions[i]);
  524. }
  525.  
  526. return { formattedResult: result, unusedSubstitutions: unusedSubstitutions };
  527. }
  528.  
  529.  
  530. function createSearchRegex(query, caseSensitive, isRegex)
  531. {
  532. var regexFlags = caseSensitive ? "g" : "gi";
  533. var regexObject;
  534.  
  535. if (isRegex) {
  536. try {
  537. regexObject = new RegExp(query, regexFlags);
  538. } catch (e) {
  539.  
  540. }
  541. }
  542.  
  543. if (!regexObject)
  544. regexObject = createPlainTextSearchRegex(query, regexFlags);
  545.  
  546. return regexObject;
  547. }
  548.  
  549.  
  550. function createPlainTextSearchRegex(query, flags)
  551. {
  552.  
  553. var regexSpecialCharacters = "[](){}+-*.,?\\^$|";
  554. var regex = "";
  555. for (var i = 0; i < query.length; ++i) {
  556. var c = query.charAt(i);
  557. if (regexSpecialCharacters.indexOf(c) != -1)
  558. regex += "\\";
  559. regex += c;
  560. }
  561. return new RegExp(regex, flags || "");
  562. }
  563.  
  564.  
  565. function countRegexMatches(regex, content)
  566. {
  567. var text = content;
  568. var result = 0;
  569. var match;
  570. while (text && (match = regex.exec(text))) {
  571. if (match[0].length > 0)
  572. ++result;
  573. text = text.substring(match.index + 1);
  574. }
  575. return result;
  576. }
  577.  
  578.  
  579. function numberToStringWithSpacesPadding(value, symbolsCount)
  580. {
  581. var numberString = value.toString();
  582. var paddingLength = Math.max(0, symbolsCount - numberString.length);
  583. var paddingString = Array(paddingLength + 1).join("\u00a0");
  584. return paddingString + numberString;
  585. }
  586.  
  587.  
  588. var Map = function()
  589. {
  590. this._map = {};
  591. this._size = 0;
  592. }
  593.  
  594. Map._lastObjectIdentifier = 0;
  595.  
  596. Map.prototype = {
  597.  
  598. put: function(key, value)
  599. {
  600. var objectIdentifier = key.__identifier;
  601. if (!objectIdentifier) {
  602. objectIdentifier = ++Map._lastObjectIdentifier;
  603. key.__identifier = objectIdentifier;
  604. }
  605. if (!this._map[objectIdentifier])
  606. ++this._size;
  607. this._map[objectIdentifier] = [key, value];
  608. },
  609.  
  610.  
  611. remove: function(key)
  612. {
  613. var result = this._map[key.__identifier];
  614. if (!result)
  615. return undefined;
  616. --this._size;
  617. delete this._map[key.__identifier];
  618. return result[1];
  619. },
  620.  
  621.  
  622. keys: function()
  623. {
  624. return this._list(0);
  625. },
  626.  
  627. values: function()
  628. {
  629. return this._list(1);
  630. },
  631.  
  632.  
  633. _list: function(index)
  634. {
  635. var result = new Array(this._size);
  636. var i = 0;
  637. for (var objectIdentifier in this._map)
  638. result[i++] = this._map[objectIdentifier][index];
  639. return result;
  640. },
  641.  
  642.  
  643. get: function(key)
  644. {
  645. var entry = this._map[key.__identifier];
  646. return entry ? entry[1] : undefined;
  647. },
  648.  
  649. size: function()
  650. {
  651. return this._size;
  652. },
  653.  
  654. clear: function()
  655. {
  656. this._map = {};
  657. this._size = 0;
  658. }
  659. }
  660.  
  661. function loadXHR(url, async, callback) 
  662. {
  663. function onReadyStateChanged() 
  664. {
  665. if (xhr.readyState !== XMLHttpRequest.DONE)
  666. return;
  667.  
  668. if (xhr.status === 200) {
  669. callback(xhr.responseText);
  670. return;
  671. }
  672.  
  673. callback(null); 
  674. }
  675.  
  676. var xhr = new XMLHttpRequest();
  677. xhr.open("GET", url, async);
  678. if (async)
  679. xhr.onreadystatechange = onReadyStateChanged;        
  680. xhr.send(null);
  681.  
  682. if (!async) {
  683. if (xhr.status === 200) 
  684. return xhr.responseText;
  685. return null;
  686. }
  687. return null;
  688. }
  689.  
  690.  
  691. function StringPool()
  692. {
  693. this.reset();
  694. }
  695.  
  696. StringPool.prototype = {
  697.  
  698. intern: function(string)
  699. {
  700.  
  701. if (string === "__proto__")
  702. return "__proto__";
  703. var result = this._strings[string];
  704. if (result === undefined) {
  705. this._strings[string] = string;
  706. result = string;
  707. }
  708. return result;
  709. },
  710.  
  711. reset: function()
  712. {
  713. this._strings = Object.create(null);
  714. },
  715.  
  716.  
  717. internObjectStrings: function(obj, depthLimit)
  718. {
  719. if (typeof depthLimit !== "number")
  720. depthLimit = 100;
  721. else if (--depthLimit < 0)
  722. throw "recursion depth limit reached in StringPool.deepIntern(), perhaps attempting to traverse cyclical references?";
  723.  
  724. for (var field in obj) {
  725. switch (typeof obj[field]) {
  726. case "string":
  727. obj[field] = this.intern(obj[field]);
  728. break;
  729. case "object":
  730. this.internObjectStrings(obj[field], depthLimit);
  731. break;
  732. }
  733. }
  734. }
  735. }
  736.  
  737. var _importedScripts = {};
  738.  
  739.  
  740. function importScript(scriptName)
  741. {
  742. if (_importedScripts[scriptName])
  743. return;
  744. _importedScripts[scriptName] = true;
  745. var xhr = new XMLHttpRequest();
  746. xhr.open("GET", scriptName, false);
  747. xhr.send(null);
  748. window.eval(xhr.responseText + "\n//@ sourceURL=" + scriptName);
  749. }
  750.  
  751.  
  752.  
  753.  
  754.  
  755.  
  756.  
  757. __whitespace = {" ":true, "\t":true, "\n":true, "\f":true, "\r":true};
  758.  
  759. difflib = {
  760. defaultJunkFunction: function (c) {
  761. return __whitespace.hasOwnProperty(c);
  762. },
  763.  
  764. stripLinebreaks: function (str) { return str.replace(/^[\n\r]*|[\n\r]*$/g, ""); },
  765.  
  766. stringAsLines: function (str) {
  767. var lfpos = str.indexOf("\n");
  768. var crpos = str.indexOf("\r");
  769. var linebreak = ((lfpos > -1 && crpos > -1) || crpos < 0) ? "\n" : "\r";
  770.  
  771. var lines = str.split(linebreak);
  772. for (var i = 0; i < lines.length; i++) {
  773. lines[i] = difflib.stripLinebreaks(lines[i]);
  774. }
  775.  
  776. return lines;
  777. },
  778.  
  779.  
  780. __reduce: function (func, list, initial) {
  781. if (initial != null) {
  782. var value = initial;
  783. var idx = 0;
  784. } else if (list) {
  785. var value = list[0];
  786. var idx = 1;
  787. } else {
  788. return null;
  789. }
  790.  
  791. for (; idx < list.length; idx++) {
  792. value = func(value, list[idx]);
  793. }
  794.  
  795. return value;
  796. },
  797.  
  798.  
  799. __ntuplecomp: function (a, b) {
  800. var mlen = Math.max(a.length, b.length);
  801. for (var i = 0; i < mlen; i++) {
  802. if (a[i] < b[i]) return -1;
  803. if (a[i] > b[i]) return 1;
  804. }
  805.  
  806. return a.length == b.length ? 0 : (a.length < b.length ? -1 : 1);
  807. },
  808.  
  809. __calculate_ratio: function (matches, length) {
  810. return length ? 2.0 * matches / length : 1.0;
  811. },
  812.  
  813.  
  814.  
  815.  
  816. __isindict: function (dict) {
  817. return function (key) { return dict.hasOwnProperty(key); };
  818. },
  819.  
  820.  
  821. __dictget: function (dict, key, defaultValue) {
  822. return dict.hasOwnProperty(key) ? dict[key] : defaultValue;
  823. },  
  824.  
  825. SequenceMatcher: function (a, b, isjunk) {
  826. this.set_seqs = function (a, b) {
  827. this.set_seq1(a);
  828. this.set_seq2(b);
  829. }
  830.  
  831. this.set_seq1 = function (a) {
  832. if (a == this.a) return;
  833. this.a = a;
  834. this.matching_blocks = this.opcodes = null;
  835. }
  836.  
  837. this.set_seq2 = function (b) {
  838. if (b == this.b) return;
  839. this.b = b;
  840. this.matching_blocks = this.opcodes = this.fullbcount = null;
  841. this.__chain_b();
  842. }
  843.  
  844. this.__chain_b = function () {
  845. var b = this.b;
  846. var n = b.length;
  847. var b2j = this.b2j = {};
  848. var populardict = {};
  849. for (var i = 0; i < b.length; i++) {
  850. var elt = b[i];
  851. if (b2j.hasOwnProperty(elt)) {
  852. var indices = b2j[elt];
  853. if (n >= 200 && indices.length * 100 > n) {
  854. populardict[elt] = 1;
  855. delete b2j[elt];
  856. } else {
  857. indices.push(i);
  858. }
  859. } else {
  860. b2j[elt] = [i];
  861. }
  862. }
  863.  
  864. for (var elt in populardict) {
  865. if (populardict.hasOwnProperty(elt)) {
  866. delete b2j[elt];
  867. }
  868. }
  869.  
  870. var isjunk = this.isjunk;
  871. var junkdict = {};
  872. if (isjunk) {
  873. for (var elt in populardict) {
  874. if (populardict.hasOwnProperty(elt) && isjunk(elt)) {
  875. junkdict[elt] = 1;
  876. delete populardict[elt];
  877. }
  878. }
  879. for (var elt in b2j) {
  880. if (b2j.hasOwnProperty(elt) && isjunk(elt)) {
  881. junkdict[elt] = 1;
  882. delete b2j[elt];
  883. }
  884. }
  885. }
  886.  
  887. this.isbjunk = difflib.__isindict(junkdict);
  888. this.isbpopular = difflib.__isindict(populardict);
  889. }
  890.  
  891. this.find_longest_match = function (alo, ahi, blo, bhi) {
  892. var a = this.a;
  893. var b = this.b;
  894. var b2j = this.b2j;
  895. var isbjunk = this.isbjunk;
  896. var besti = alo;
  897. var bestj = blo;
  898. var bestsize = 0;
  899. var j = null;
  900.  
  901. var j2len = {};
  902. var nothing = [];
  903. for (var i = alo; i < ahi; i++) {
  904. var newj2len = {};
  905. var jdict = difflib.__dictget(b2j, a[i], nothing);
  906. for (var jkey in jdict) {
  907. if (jdict.hasOwnProperty(jkey)) {
  908. j = jdict[jkey];
  909. if (j < blo) continue;
  910. if (j >= bhi) break;
  911. newj2len[j] = k = difflib.__dictget(j2len, j - 1, 0) + 1;
  912. if (k > bestsize) {
  913. besti = i - k + 1;
  914. bestj = j - k + 1;
  915. bestsize = k;
  916. }
  917. }
  918. }
  919. j2len = newj2len;
  920. }
  921.  
  922. while (besti > alo && bestj > blo && !isbjunk(b[bestj - 1]) && a[besti - 1] == b[bestj - 1]) {
  923. besti--;
  924. bestj--;
  925. bestsize++;
  926. }
  927.  
  928. while (besti + bestsize < ahi && bestj + bestsize < bhi &&
  929. !isbjunk(b[bestj + bestsize]) &&
  930. a[besti + bestsize] == b[bestj + bestsize]) {
  931. bestsize++;
  932. }
  933.  
  934. while (besti > alo && bestj > blo && isbjunk(b[bestj - 1]) && a[besti - 1] == b[bestj - 1]) {
  935. besti--;
  936. bestj--;
  937. bestsize++;
  938. }
  939.  
  940. while (besti + bestsize < ahi && bestj + bestsize < bhi && isbjunk(b[bestj + bestsize]) &&
  941. a[besti + bestsize] == b[bestj + bestsize]) {
  942. bestsize++;
  943. }
  944.  
  945. return [besti, bestj, bestsize];
  946. }
  947.  
  948. this.get_matching_blocks = function () {
  949. if (this.matching_blocks != null) return this.matching_blocks;
  950. var la = this.a.length;
  951. var lb = this.b.length;
  952.  
  953. var queue = [[0, la, 0, lb]];
  954. var matching_blocks = [];
  955. var alo, ahi, blo, bhi, qi, i, j, k, x;
  956. while (queue.length) {
  957. qi = queue.pop();
  958. alo = qi[0];
  959. ahi = qi[1];
  960. blo = qi[2];
  961. bhi = qi[3];
  962. x = this.find_longest_match(alo, ahi, blo, bhi);
  963. i = x[0];
  964. j = x[1];
  965. k = x[2];
  966.  
  967. if (k) {
  968. matching_blocks.push(x);
  969. if (alo < i && blo < j)
  970. queue.push([alo, i, blo, j]);
  971. if (i+k < ahi && j+k < bhi)
  972. queue.push([i + k, ahi, j + k, bhi]);
  973. }
  974. }
  975.  
  976. matching_blocks.sort(difflib.__ntuplecomp);
  977.  
  978. var i1 = j1 = k1 = block = 0;
  979. var non_adjacent = [];
  980. for (var idx in matching_blocks) {
  981. if (matching_blocks.hasOwnProperty(idx)) {
  982. block = matching_blocks[idx];
  983. i2 = block[0];
  984. j2 = block[1];
  985. k2 = block[2];
  986. if (i1 + k1 == i2 && j1 + k1 == j2) {
  987. k1 += k2;
  988. } else {
  989. if (k1) non_adjacent.push([i1, j1, k1]);
  990. i1 = i2;
  991. j1 = j2;
  992. k1 = k2;
  993. }
  994. }
  995. }
  996.  
  997. if (k1) non_adjacent.push([i1, j1, k1]);
  998.  
  999. non_adjacent.push([la, lb, 0]);
  1000. this.matching_blocks = non_adjacent;
  1001. return this.matching_blocks;
  1002. }
  1003.  
  1004. this.get_opcodes = function () {
  1005. if (this.opcodes != null) return this.opcodes;
  1006. var i = 0;
  1007. var j = 0;
  1008. var answer = [];
  1009. this.opcodes = answer;
  1010. var block, ai, bj, size, tag;
  1011. var blocks = this.get_matching_blocks();
  1012. for (var idx in blocks) {
  1013. if (blocks.hasOwnProperty(idx)) {
  1014. block = blocks[idx];
  1015. ai = block[0];
  1016. bj = block[1];
  1017. size = block[2];
  1018. tag = '';
  1019. if (i < ai && j < bj) {
  1020. tag = 'replace';
  1021. } else if (i < ai) {
  1022. tag = 'delete';
  1023. } else if (j < bj) {
  1024. tag = 'insert';
  1025. }
  1026. if (tag) answer.push([tag, i, ai, j, bj]);
  1027. i = ai + size;
  1028. j = bj + size;
  1029.  
  1030. if (size) answer.push(['equal', ai, i, bj, j]);
  1031. }
  1032. }
  1033.  
  1034. return answer;
  1035. }
  1036.  
  1037.  
  1038.  
  1039. this.get_grouped_opcodes = function (n) {
  1040. if (!n) n = 3;
  1041. var codes = this.get_opcodes();
  1042. if (!codes) codes = [["equal", 0, 1, 0, 1]];
  1043. var code, tag, i1, i2, j1, j2;
  1044. if (codes[0][0] == 'equal') {
  1045. code = codes[0];
  1046. tag = code[0];
  1047. i1 = code[1];
  1048. i2 = code[2];
  1049. j1 = code[3];
  1050. j2 = code[4];
  1051. codes[0] = [tag, Math.max(i1, i2 - n), i2, Math.max(j1, j2 - n), j2];
  1052. }
  1053. if (codes[codes.length - 1][0] == 'equal') {
  1054. code = codes[codes.length - 1];
  1055. tag = code[0];
  1056. i1 = code[1];
  1057. i2 = code[2];
  1058. j1 = code[3];
  1059. j2 = code[4];
  1060. codes[codes.length - 1] = [tag, i1, Math.min(i2, i1 + n), j1, Math.min(j2, j1 + n)];
  1061. }
  1062.  
  1063. var nn = n + n;
  1064. var groups = [];
  1065. for (var idx in codes) {
  1066. if (codes.hasOwnProperty(idx)) {
  1067. code = codes[idx];
  1068. tag = code[0];
  1069. i1 = code[1];
  1070. i2 = code[2];
  1071. j1 = code[3];
  1072. j2 = code[4];
  1073. if (tag == 'equal' && i2 - i1 > nn) {
  1074. groups.push([tag, i1, Math.min(i2, i1 + n), j1, Math.min(j2, j1 + n)]);
  1075. i1 = Math.max(i1, i2-n);
  1076. j1 = Math.max(j1, j2-n);
  1077. }
  1078.  
  1079. groups.push([tag, i1, i2, j1, j2]);
  1080. }
  1081. }
  1082.  
  1083. if (groups && groups[groups.length - 1][0] == 'equal') groups.pop();
  1084.  
  1085. return groups;
  1086. }
  1087.  
  1088. this.ratio = function () {
  1089. matches = difflib.__reduce(
  1090. function (sum, triple) { return sum + triple[triple.length - 1]; },
  1091. this.get_matching_blocks(), 0);
  1092. return difflib.__calculate_ratio(matches, this.a.length + this.b.length);
  1093. }
  1094.  
  1095. this.quick_ratio = function () {
  1096. var fullbcount, elt;
  1097. if (this.fullbcount == null) {
  1098. this.fullbcount = fullbcount = {};
  1099. for (var i = 0; i < this.b.length; i++) {
  1100. elt = this.b[i];
  1101. fullbcount[elt] = difflib.__dictget(fullbcount, elt, 0) + 1;
  1102. }
  1103. }
  1104. fullbcount = this.fullbcount;
  1105.  
  1106. var avail = {};
  1107. var availhas = difflib.__isindict(avail);
  1108. var matches = numb = 0;
  1109. for (var i = 0; i < this.a.length; i++) {
  1110. elt = this.a[i];
  1111. if (availhas(elt)) {
  1112. numb = avail[elt];
  1113. } else {
  1114. numb = difflib.__dictget(fullbcount, elt, 0);
  1115. }
  1116. avail[elt] = numb - 1;
  1117. if (numb > 0) matches++;
  1118. }
  1119.  
  1120. return difflib.__calculate_ratio(matches, this.a.length + this.b.length);
  1121. }
  1122.  
  1123. this.real_quick_ratio = function () {
  1124. var la = this.a.length;
  1125. var lb = this.b.length;
  1126. return _calculate_ratio(Math.min(la, lb), la + lb);
  1127. }
  1128.  
  1129. this.isjunk = isjunk ? isjunk : difflib.defaultJunkFunction;
  1130. this.a = this.b = null;
  1131. this.set_seqs(a, b);
  1132. }
  1133. }
  1134.  
  1135.  
  1136.  
  1137.  
  1138.  
  1139.  
  1140. Node.prototype.rangeOfWord = function(offset, stopCharacters, stayWithinNode, direction)
  1141. {
  1142. var startNode;
  1143. var startOffset = 0;
  1144. var endNode;
  1145. var endOffset = 0;
  1146.  
  1147. if (!stayWithinNode)
  1148. stayWithinNode = this;
  1149.  
  1150. if (!direction || direction === "backward" || direction === "both") {
  1151. var node = this;
  1152. while (node) {
  1153. if (node === stayWithinNode) {
  1154. if (!startNode)
  1155. startNode = stayWithinNode;
  1156. break;
  1157. }
  1158.  
  1159. if (node.nodeType === Node.TEXT_NODE) {
  1160. var start = (node === this ? (offset - 1) : (node.nodeValue.length - 1));
  1161. for (var i = start; i >= 0; --i) {
  1162. if (stopCharacters.indexOf(node.nodeValue[i]) !== -1) {
  1163. startNode = node;
  1164. startOffset = i + 1;
  1165. break;
  1166. }
  1167. }
  1168. }
  1169.  
  1170. if (startNode)
  1171. break;
  1172.  
  1173. node = node.traversePreviousNode(stayWithinNode);
  1174. }
  1175.  
  1176. if (!startNode) {
  1177. startNode = stayWithinNode;
  1178. startOffset = 0;
  1179. }
  1180. } else {
  1181. startNode = this;
  1182. startOffset = offset;
  1183. }
  1184.  
  1185. if (!direction || direction === "forward" || direction === "both") {
  1186. node = this;
  1187. while (node) {
  1188. if (node === stayWithinNode) {
  1189. if (!endNode)
  1190. endNode = stayWithinNode;
  1191. break;
  1192. }
  1193.  
  1194. if (node.nodeType === Node.TEXT_NODE) {
  1195. var start = (node === this ? offset : 0);
  1196. for (var i = start; i < node.nodeValue.length; ++i) {
  1197. if (stopCharacters.indexOf(node.nodeValue[i]) !== -1) {
  1198. endNode = node;
  1199. endOffset = i;
  1200. break;
  1201. }
  1202. }
  1203. }
  1204.  
  1205. if (endNode)
  1206. break;
  1207.  
  1208. node = node.traverseNextNode(stayWithinNode);
  1209. }
  1210.  
  1211. if (!endNode) {
  1212. endNode = stayWithinNode;
  1213. endOffset = stayWithinNode.nodeType === Node.TEXT_NODE ? stayWithinNode.nodeValue.length : stayWithinNode.childNodes.length;
  1214. }
  1215. } else {
  1216. endNode = this;
  1217. endOffset = offset;
  1218. }
  1219.  
  1220. var result = this.ownerDocument.createRange();
  1221. result.setStart(startNode, startOffset);
  1222. result.setEnd(endNode, endOffset);
  1223.  
  1224. return result;
  1225. }
  1226.  
  1227. Node.prototype.traverseNextTextNode = function(stayWithin)
  1228. {
  1229. var node = this.traverseNextNode(stayWithin);
  1230. if (!node)
  1231. return;
  1232.  
  1233. while (node && node.nodeType !== Node.TEXT_NODE)
  1234. node = node.traverseNextNode(stayWithin);
  1235.  
  1236. return node;
  1237. }
  1238.  
  1239. Node.prototype.rangeBoundaryForOffset = function(offset)
  1240. {
  1241. var node = this.traverseNextTextNode(this);
  1242. while (node && offset > node.nodeValue.length) {
  1243. offset -= node.nodeValue.length;
  1244. node = node.traverseNextTextNode(this);
  1245. }
  1246. if (!node)
  1247. return { container: this, offset: 0 };
  1248. return { container: node, offset: offset };
  1249. }
  1250.  
  1251. Element.prototype.removeStyleClass = function(className)
  1252. {
  1253. this.classList.remove(className);
  1254. }
  1255.  
  1256. Element.prototype.removeMatchingStyleClasses = function(classNameRegex)
  1257. {
  1258. var regex = new RegExp("(^|\\s+)" + classNameRegex + "($|\\s+)");
  1259. if (regex.test(this.className))
  1260. this.className = this.className.replace(regex, " ");
  1261. }
  1262.  
  1263. Element.prototype.addStyleClass = function(className)
  1264. {
  1265. this.classList.add(className);
  1266. }
  1267.  
  1268. Element.prototype.hasStyleClass = function(className)
  1269. {
  1270. return this.classList.contains(className);
  1271. }
  1272.  
  1273.  
  1274. Element.prototype.positionAt = function(x, y)
  1275. {
  1276. if (typeof x === "number")
  1277. this.style.setProperty("left", x + "px");
  1278. else
  1279. this.style.removeProperty("left");
  1280.  
  1281. if (typeof y === "number")
  1282. this.style.setProperty("top", y + "px");
  1283. else
  1284. this.style.removeProperty("top");
  1285. }
  1286.  
  1287. Element.prototype.isScrolledToBottom = function()
  1288. {
  1289.  
  1290. return this.scrollTop + this.clientHeight === this.scrollHeight;
  1291. }
  1292.  
  1293. Element.prototype.remove = function()
  1294. {
  1295. if (this.parentElement)
  1296. this.parentElement.removeChild(this);
  1297. }
  1298.  
  1299.  
  1300. function removeSubsequentNodes(fromNode, toNode)
  1301. {
  1302. for (var node = fromNode; node && node !== toNode; ) {
  1303. var nodeToRemove = node;
  1304. node = node.nextSibling;
  1305. nodeToRemove.remove();
  1306. }
  1307. }
  1308.  
  1309.  
  1310. function Size(width, height)
  1311. {
  1312. this.width = width;
  1313. this.height = height;
  1314. }
  1315.  
  1316.  
  1317. Element.prototype.measurePreferredSize = function()
  1318. {
  1319. document.body.appendChild(this);
  1320. this.positionAt(0, 0);
  1321. var result = new Size(this.offsetWidth, this.offsetHeight);
  1322. this.positionAt(undefined, undefined);
  1323. document.body.removeChild(this);
  1324. return result;
  1325. }
  1326.  
  1327. Node.prototype.enclosingNodeOrSelfWithNodeNameInArray = function(nameArray)
  1328. {
  1329. for (var node = this; node && node !== this.ownerDocument; node = node.parentNode)
  1330. for (var i = 0; i < nameArray.length; ++i)
  1331. if (node.nodeName.toLowerCase() === nameArray[i].toLowerCase())
  1332. return node;
  1333. return null;
  1334. }
  1335.  
  1336. Node.prototype.enclosingNodeOrSelfWithNodeName = function(nodeName)
  1337. {
  1338. return this.enclosingNodeOrSelfWithNodeNameInArray([nodeName]);
  1339. }
  1340.  
  1341. Node.prototype.enclosingNodeOrSelfWithClass = function(className)
  1342. {
  1343. for (var node = this; node && node !== this.ownerDocument; node = node.parentNode)
  1344. if (node.nodeType === Node.ELEMENT_NODE && node.hasStyleClass(className))
  1345. return node;
  1346. return null;
  1347. }
  1348.  
  1349. Element.prototype.query = function(query)
  1350. {
  1351. return this.ownerDocument.evaluate(query, this, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  1352. }
  1353.  
  1354. Element.prototype.removeChildren = function()
  1355. {
  1356. if (this.firstChild)
  1357. this.textContent = "";
  1358. }
  1359.  
  1360. Element.prototype.isInsertionCaretInside = function()
  1361. {
  1362. var selection = window.getSelection();
  1363. if (!selection.rangeCount || !selection.isCollapsed)
  1364. return false;
  1365. var selectionRange = selection.getRangeAt(0);
  1366. return selectionRange.startContainer.isSelfOrDescendant(this);
  1367. }
  1368.  
  1369.  
  1370. Element.prototype.createChild = function(elementName, className)
  1371. {
  1372. var element = this.ownerDocument.createElement(elementName);
  1373. if (className)
  1374. element.className = className;
  1375. this.appendChild(element);
  1376. return element;
  1377. }
  1378.  
  1379. DocumentFragment.prototype.createChild = Element.prototype.createChild;
  1380.  
  1381.  
  1382. Element.prototype.createTextChild = function(text)
  1383. {
  1384. var element = this.ownerDocument.createTextNode(text);
  1385. this.appendChild(element);
  1386. return element;
  1387. }
  1388.  
  1389. DocumentFragment.prototype.createTextChild = Element.prototype.createTextChild;
  1390.  
  1391.  
  1392. Element.prototype.totalOffsetLeft = function()
  1393. {
  1394. return this.totalOffset().left;
  1395. }
  1396.  
  1397.  
  1398. Element.prototype.totalOffsetTop = function()
  1399. {
  1400. return this.totalOffset().top;
  1401.  
  1402. }
  1403.  
  1404. Element.prototype.totalOffset = function()
  1405. {
  1406. var totalLeft = 0;
  1407. var totalTop = 0;
  1408.  
  1409. for (var element = this; element; element = element.offsetParent) {
  1410. totalLeft += element.offsetLeft;
  1411. totalTop += element.offsetTop;
  1412. if (this !== element) {
  1413. totalLeft += element.clientLeft - element.scrollLeft;
  1414. totalTop += element.clientTop - element.scrollTop;
  1415. }
  1416. }
  1417.  
  1418. return { left: totalLeft, top: totalTop };
  1419. }
  1420.  
  1421. Element.prototype.scrollOffset = function()
  1422. {
  1423. var curLeft = 0;
  1424. var curTop = 0;
  1425. for (var element = this; element; element = element.scrollParent) {
  1426. curLeft += element.scrollLeft;
  1427. curTop += element.scrollTop;
  1428. }
  1429. return { left: curLeft, top: curTop };
  1430. }
  1431.  
  1432.  
  1433. function AnchorBox(x, y, width, height)
  1434. {
  1435. this.x = x || 0;
  1436. this.y = y || 0;
  1437. this.width = width || 0;
  1438. this.height = height || 0;
  1439. }
  1440.  
  1441.  
  1442. Element.prototype.offsetRelativeToWindow = function(targetWindow)
  1443. {
  1444. var elementOffset = new AnchorBox();
  1445. var curElement = this;
  1446. var curWindow = this.ownerDocument.defaultView;
  1447. while (curWindow && curElement) {
  1448. elementOffset.x += curElement.totalOffsetLeft();
  1449. elementOffset.y += curElement.totalOffsetTop();
  1450. if (curWindow === targetWindow)
  1451. break;
  1452.  
  1453. curElement = curWindow.frameElement;
  1454. curWindow = curWindow.parent;
  1455. }
  1456.  
  1457. return elementOffset;
  1458. }
  1459.  
  1460.  
  1461. Element.prototype.boxInWindow = function(targetWindow)
  1462. {
  1463. targetWindow = targetWindow || this.ownerDocument.defaultView;
  1464.  
  1465. var anchorBox = this.offsetRelativeToWindow(window);
  1466. anchorBox.width = Math.min(this.offsetWidth, window.innerWidth - anchorBox.x);
  1467. anchorBox.height = Math.min(this.offsetHeight, window.innerHeight - anchorBox.y);
  1468.  
  1469. return anchorBox;
  1470. }
  1471.  
  1472.  
  1473. Element.prototype.setTextAndTitle = function(text)
  1474. {
  1475. this.textContent = text;
  1476. this.title = text;
  1477. }
  1478.  
  1479. KeyboardEvent.prototype.__defineGetter__("data", function()
  1480. {
  1481.  
  1482.  
  1483. switch (this.type) {
  1484. case "keypress":
  1485. if (!this.ctrlKey && !this.metaKey)
  1486. return String.fromCharCode(this.charCode);
  1487. else
  1488. return "";
  1489. case "keydown":
  1490. case "keyup":
  1491. if (!this.ctrlKey && !this.metaKey && !this.altKey)
  1492. return String.fromCharCode(this.which);
  1493. else
  1494. return "";
  1495. }
  1496. });
  1497.  
  1498.  
  1499. Event.prototype.consume = function(preventDefault)
  1500. {
  1501. this.stopImmediatePropagation();
  1502. if (preventDefault)
  1503. this.preventDefault();
  1504. this.handled = true;
  1505. }
  1506.  
  1507. Text.prototype.select = function(start, end)
  1508. {
  1509. start = start || 0;
  1510. end = end || this.textContent.length;
  1511.  
  1512. if (start < 0)
  1513. start = end + start;
  1514.  
  1515. var selection = this.ownerDocument.defaultView.getSelection();
  1516. selection.removeAllRanges();
  1517. var range = this.ownerDocument.createRange();
  1518. range.setStart(this, start);
  1519. range.setEnd(this, end);
  1520. selection.addRange(range);
  1521. return this;
  1522. }
  1523.  
  1524. Element.prototype.selectionLeftOffset = function()
  1525. {
  1526.  
  1527.  
  1528. var selection = window.getSelection();
  1529. if (!selection.containsNode(this, true))
  1530. return null;
  1531.  
  1532. var leftOffset = selection.anchorOffset;
  1533. var node = selection.anchorNode;
  1534.  
  1535. while (node !== this) {
  1536. while (node.previousSibling) {
  1537. node = node.previousSibling;
  1538. leftOffset += node.textContent.length;
  1539. }
  1540. node = node.parentNode;
  1541. }
  1542.  
  1543. return leftOffset;
  1544. }
  1545.  
  1546. Node.prototype.isAncestor = function(node)
  1547. {
  1548. if (!node)
  1549. return false;
  1550.  
  1551. var currentNode = node.parentNode;
  1552. while (currentNode) {
  1553. if (this === currentNode)
  1554. return true;
  1555. currentNode = currentNode.parentNode;
  1556. }
  1557. return false;
  1558. }
  1559.  
  1560. Node.prototype.isDescendant = function(descendant)
  1561. {
  1562. return !!descendant && descendant.isAncestor(this);
  1563. }
  1564.  
  1565. Node.prototype.isSelfOrAncestor = function(node)
  1566. {
  1567. return !!node && (node === this || this.isAncestor(node));
  1568. }
  1569.  
  1570. Node.prototype.isSelfOrDescendant = function(node)
  1571. {
  1572. return !!node && (node === this || this.isDescendant(node));
  1573. }
  1574.  
  1575. Node.prototype.traverseNextNode = function(stayWithin)
  1576. {
  1577. var node = this.firstChild;
  1578. if (node)
  1579. return node;
  1580.  
  1581. if (stayWithin && this === stayWithin)
  1582. return null;
  1583.  
  1584. node = this.nextSibling;
  1585. if (node)
  1586. return node;
  1587.  
  1588. node = this;
  1589. while (node && !node.nextSibling && (!stayWithin || !node.parentNode || node.parentNode !== stayWithin))
  1590. node = node.parentNode;
  1591. if (!node)
  1592. return null;
  1593.  
  1594. return node.nextSibling;
  1595. }
  1596.  
  1597. Node.prototype.traversePreviousNode = function(stayWithin)
  1598. {
  1599. if (stayWithin && this === stayWithin)
  1600. return null;
  1601. var node = this.previousSibling;
  1602. while (node && node.lastChild)
  1603. node = node.lastChild;
  1604. if (node)
  1605. return node;
  1606. return this.parentNode;
  1607. }
  1608.  
  1609. function isEnterKey(event) {
  1610.  
  1611. return event.keyCode !== 229 && event.keyIdentifier === "Enter";
  1612. }
  1613.  
  1614. function consumeEvent(e)
  1615. {
  1616. e.consume();
  1617. }
  1618.  
  1619.  
  1620. function NonLeakingMutationObserver(handler)
  1621. {
  1622. this._observer = new WebKitMutationObserver(handler);
  1623. NonLeakingMutationObserver._instances.push(this);
  1624. if (!window.testRunner && !window.isUnderTest && !NonLeakingMutationObserver._unloadListener) {
  1625. NonLeakingMutationObserver._unloadListener = function() {
  1626. while (NonLeakingMutationObserver._instances.length)
  1627. NonLeakingMutationObserver._instances[NonLeakingMutationObserver._instances.length - 1].disconnect();
  1628. };
  1629. window.addEventListener("unload", NonLeakingMutationObserver._unloadListener, false);
  1630. }
  1631. }
  1632.  
  1633. NonLeakingMutationObserver._instances = [];
  1634.  
  1635. NonLeakingMutationObserver.prototype = {
  1636.  
  1637. observe: function(element, config)
  1638. {
  1639. if (this._observer)
  1640. this._observer.observe(element, config);
  1641. },
  1642.  
  1643. disconnect: function()
  1644. {
  1645. if (this._observer)
  1646. this._observer.disconnect();
  1647. NonLeakingMutationObserver._instances.remove(this);
  1648. delete this._observer;
  1649. }
  1650. }
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657.  
  1658. function TreeOutline(listNode, nonFocusable)
  1659. {
  1660.  
  1661. this.children = [];
  1662. this.selectedTreeElement = null;
  1663. this._childrenListNode = listNode;
  1664. this.childrenListElement = this._childrenListNode;
  1665. this._childrenListNode.removeChildren();
  1666. this.expandTreeElementsWhenArrowing = false;
  1667. this.root = true;
  1668. this.hasChildren = false;
  1669. this.expanded = true;
  1670. this.selected = false;
  1671. this.treeOutline = this;
  1672. this.comparator = null;
  1673. this.searchable = false;
  1674. this.searchInputElement = null;
  1675.  
  1676. this.setFocusable(!nonFocusable);
  1677. this._childrenListNode.addEventListener("keydown", this._treeKeyDown.bind(this), true);
  1678. this._childrenListNode.addEventListener("keypress", this._treeKeyPress.bind(this), true);
  1679.  
  1680. this._treeElementsMap = new Map();
  1681. this._expandedStateMap = new Map();
  1682. }
  1683.  
  1684. TreeOutline.prototype.setFocusable = function(focusable)
  1685. {
  1686. if (focusable)
  1687. this._childrenListNode.setAttribute("tabIndex", 0);
  1688. else
  1689. this._childrenListNode.removeAttribute("tabIndex");
  1690. }
  1691.  
  1692. TreeOutline.prototype.appendChild = function(child)
  1693. {
  1694. var insertionIndex;
  1695. if (this.treeOutline.comparator)
  1696. insertionIndex = insertionIndexForObjectInListSortedByFunction(child, this.children, this.treeOutline.comparator);
  1697. else
  1698. insertionIndex = this.children.length;
  1699. this.insertChild(child, insertionIndex);
  1700. }
  1701.  
  1702. TreeOutline.prototype.insertChild = function(child, index)
  1703. {
  1704. if (!child)
  1705. throw("child can't be undefined or null");
  1706.  
  1707. var previousChild = (index > 0 ? this.children[index - 1] : null);
  1708. if (previousChild) {
  1709. previousChild.nextSibling = child;
  1710. child.previousSibling = previousChild;
  1711. } else {
  1712. child.previousSibling = null;
  1713. }
  1714.  
  1715. var nextChild = this.children[index];
  1716. if (nextChild) {
  1717. nextChild.previousSibling = child;
  1718. child.nextSibling = nextChild;
  1719. } else {
  1720. child.nextSibling = null;
  1721. }
  1722.  
  1723. this.children.splice(index, 0, child);
  1724. this.hasChildren = true;
  1725. child.parent = this;
  1726. child.treeOutline = this.treeOutline;
  1727. child.treeOutline._rememberTreeElement(child);
  1728.  
  1729. var current = child.children[0];
  1730. while (current) {
  1731. current.treeOutline = this.treeOutline;
  1732. current.treeOutline._rememberTreeElement(current);
  1733. current = current.traverseNextTreeElement(false, child, true);
  1734. }
  1735.  
  1736. if (child.hasChildren && typeof(child.treeOutline._expandedStateMap.get(child.representedObject)) !== "undefined")
  1737. child.expanded = child.treeOutline._expandedStateMap.get(child.representedObject);
  1738.  
  1739. if (!this._childrenListNode) {
  1740. this._childrenListNode = this.treeOutline._childrenListNode.ownerDocument.createElement("ol");
  1741. this._childrenListNode.parentTreeElement = this;
  1742. this._childrenListNode.classList.add("children");
  1743. if (this.hidden)
  1744. this._childrenListNode.classList.add("hidden");
  1745. }
  1746.  
  1747. child._attach();
  1748. }
  1749.  
  1750. TreeOutline.prototype.removeChildAtIndex = function(childIndex)
  1751. {
  1752. if (childIndex < 0 || childIndex >= this.children.length)
  1753. throw("childIndex out of range");
  1754.  
  1755. var child = this.children[childIndex];
  1756. this.children.splice(childIndex, 1);
  1757.  
  1758. var parent = child.parent;
  1759. if (child.deselect()) {
  1760. if (child.previousSibling)
  1761. child.previousSibling.select();
  1762. else if (child.nextSibling)
  1763. child.nextSibling.select();
  1764. else
  1765. parent.select();
  1766. }
  1767.  
  1768. if (child.previousSibling)
  1769. child.previousSibling.nextSibling = child.nextSibling;
  1770. if (child.nextSibling)
  1771. child.nextSibling.previousSibling = child.previousSibling;
  1772.  
  1773. if (child.treeOutline) {
  1774. child.treeOutline._forgetTreeElement(child);
  1775. child.treeOutline._forgetChildrenRecursive(child);
  1776. }
  1777.  
  1778. child._detach();
  1779. child.treeOutline = null;
  1780. child.parent = null;
  1781. child.nextSibling = null;
  1782. child.previousSibling = null;
  1783. }
  1784.  
  1785. TreeOutline.prototype.removeChild = function(child)
  1786. {
  1787. if (!child)
  1788. throw("child can't be undefined or null");
  1789.  
  1790. var childIndex = this.children.indexOf(child);
  1791. if (childIndex === -1)
  1792. throw("child not found in this node's children");
  1793.  
  1794. this.removeChildAtIndex.call(this, childIndex);
  1795. }
  1796.  
  1797. TreeOutline.prototype.removeChildren = function()
  1798. {
  1799. for (var i = 0; i < this.children.length; ++i) {
  1800. var child = this.children[i];
  1801. child.deselect();
  1802.  
  1803. if (child.treeOutline) {
  1804. child.treeOutline._forgetTreeElement(child);
  1805. child.treeOutline._forgetChildrenRecursive(child);
  1806. }
  1807.  
  1808. child._detach();
  1809. child.treeOutline = null;
  1810. child.parent = null;
  1811. child.nextSibling = null;
  1812. child.previousSibling = null;
  1813. }
  1814.  
  1815. this.children = [];
  1816. }
  1817.  
  1818. TreeOutline.prototype._rememberTreeElement = function(element)
  1819. {
  1820. if (!this._treeElementsMap.get(element.representedObject))
  1821. this._treeElementsMap.put(element.representedObject, []);
  1822.  
  1823.  
  1824. var elements = this._treeElementsMap.get(element.representedObject);
  1825. if (elements.indexOf(element) !== -1)
  1826. return;
  1827.  
  1828.  
  1829. elements.push(element);
  1830. }
  1831.  
  1832. TreeOutline.prototype._forgetTreeElement = function(element)
  1833. {
  1834. if (this._treeElementsMap.get(element.representedObject)) {
  1835. var elements = this._treeElementsMap.get(element.representedObject);
  1836. elements.remove(element, true);
  1837. if (!elements.length)
  1838. this._treeElementsMap.remove(element.representedObject);
  1839. }
  1840. }
  1841.  
  1842. TreeOutline.prototype._forgetChildrenRecursive = function(parentElement)
  1843. {
  1844. var child = parentElement.children[0];
  1845. while (child) {
  1846. this._forgetTreeElement(child);
  1847. child = child.traverseNextTreeElement(false, parentElement, true);
  1848. }
  1849. }
  1850.  
  1851. TreeOutline.prototype.getCachedTreeElement = function(representedObject)
  1852. {
  1853. if (!representedObject)
  1854. return null;
  1855.  
  1856. var elements = this._treeElementsMap.get(representedObject);
  1857. if (elements && elements.length)
  1858. return elements[0];
  1859. return null;
  1860. }
  1861.  
  1862. TreeOutline.prototype.findTreeElement = function(representedObject, isAncestor, getParent)
  1863. {
  1864. if (!representedObject)
  1865. return null;
  1866.  
  1867. var cachedElement = this.getCachedTreeElement(representedObject);
  1868. if (cachedElement)
  1869. return cachedElement;
  1870.  
  1871.  
  1872. var ancestors = [];
  1873. for (var currentObject = getParent(representedObject); currentObject;  currentObject = getParent(currentObject)) {
  1874. ancestors.push(currentObject);
  1875. if (this.getCachedTreeElement(currentObject))  
  1876. break;
  1877. }
  1878.  
  1879. if (!currentObject)
  1880. return null;
  1881.  
  1882.  
  1883. for (var i = ancestors.length - 1; i >= 0; --i) {
  1884. var treeElement = this.getCachedTreeElement(ancestors[i]);
  1885. if (treeElement)
  1886. treeElement.onpopulate();  
  1887. }
  1888.  
  1889. return this.getCachedTreeElement(representedObject);
  1890. }
  1891.  
  1892. TreeOutline.prototype.treeElementFromPoint = function(x, y)
  1893. {
  1894. var node = this._childrenListNode.ownerDocument.elementFromPoint(x, y);
  1895. if (!node)
  1896. return null;
  1897.  
  1898. var listNode = node.enclosingNodeOrSelfWithNodeNameInArray(["ol", "li"]);
  1899. if (listNode)
  1900. return listNode.parentTreeElement || listNode.treeElement;
  1901. return null;
  1902. }
  1903.  
  1904. TreeOutline.prototype._treeKeyPress = function(event)
  1905. {
  1906. if (!this.searchable || WebInspector.isBeingEdited(this._childrenListNode))
  1907. return;
  1908.  
  1909. var searchText = String.fromCharCode(event.charCode);
  1910.  
  1911. if (searchText.trim() !== searchText)
  1912. return;
  1913.  
  1914. this._startSearch(searchText);
  1915. event.consume(true);
  1916. }
  1917.  
  1918. TreeOutline.prototype._treeKeyDown = function(event)
  1919. {
  1920. if (event.target !== this._childrenListNode)
  1921. return;
  1922.  
  1923. if (!this.selectedTreeElement || event.shiftKey || event.metaKey || event.ctrlKey)
  1924. return;
  1925.  
  1926. var handled = false;
  1927. var nextSelectedElement;
  1928. if (event.keyIdentifier === "Up" && !event.altKey) {
  1929. nextSelectedElement = this.selectedTreeElement.traversePreviousTreeElement(true);
  1930. while (nextSelectedElement && !nextSelectedElement.selectable)
  1931. nextSelectedElement = nextSelectedElement.traversePreviousTreeElement(!this.expandTreeElementsWhenArrowing);
  1932. handled = nextSelectedElement ? true : false;
  1933. } else if (event.keyIdentifier === "Down" && !event.altKey) {
  1934. nextSelectedElement = this.selectedTreeElement.traverseNextTreeElement(true);
  1935. while (nextSelectedElement && !nextSelectedElement.selectable)
  1936. nextSelectedElement = nextSelectedElement.traverseNextTreeElement(!this.expandTreeElementsWhenArrowing);
  1937. handled = nextSelectedElement ? true : false;
  1938. } else if (event.keyIdentifier === "Left") {
  1939. if (this.selectedTreeElement.expanded) {
  1940. if (event.altKey)
  1941. this.selectedTreeElement.collapseRecursively();
  1942. else
  1943. this.selectedTreeElement.collapse();
  1944. handled = true;
  1945. } else if (this.selectedTreeElement.parent && !this.selectedTreeElement.parent.root) {
  1946. handled = true;
  1947. if (this.selectedTreeElement.parent.selectable) {
  1948. nextSelectedElement = this.selectedTreeElement.parent;
  1949. while (nextSelectedElement && !nextSelectedElement.selectable)
  1950. nextSelectedElement = nextSelectedElement.parent;
  1951. handled = nextSelectedElement ? true : false;
  1952. } else if (this.selectedTreeElement.parent)
  1953. this.selectedTreeElement.parent.collapse();
  1954. }
  1955. } else if (event.keyIdentifier === "Right") {
  1956. if (!this.selectedTreeElement.revealed()) {
  1957. this.selectedTreeElement.reveal();
  1958. handled = true;
  1959. } else if (this.selectedTreeElement.hasChildren) {
  1960. handled = true;
  1961. if (this.selectedTreeElement.expanded) {
  1962. nextSelectedElement = this.selectedTreeElement.children[0];
  1963. while (nextSelectedElement && !nextSelectedElement.selectable)
  1964. nextSelectedElement = nextSelectedElement.nextSibling;
  1965. handled = nextSelectedElement ? true : false;
  1966. } else {
  1967. if (event.altKey)
  1968. this.selectedTreeElement.expandRecursively();
  1969. else
  1970. this.selectedTreeElement.expand();
  1971. }
  1972. }
  1973. } else if (event.keyCode === 8   || event.keyCode === 46  )
  1974. handled = this.selectedTreeElement.ondelete();
  1975. else if (isEnterKey(event))
  1976. handled = this.selectedTreeElement.onenter();
  1977. else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Space.code)
  1978. handled = this.selectedTreeElement.onspace();
  1979.  
  1980. if (nextSelectedElement) {
  1981. nextSelectedElement.reveal();
  1982. nextSelectedElement.select(false, true);
  1983. }
  1984.  
  1985. if (handled)
  1986. event.consume(true);
  1987. }
  1988.  
  1989. TreeOutline.prototype.expand = function()
  1990. {
  1991.  
  1992. }
  1993.  
  1994. TreeOutline.prototype.collapse = function()
  1995. {
  1996.  
  1997. }
  1998.  
  1999. TreeOutline.prototype.revealed = function()
  2000. {
  2001. return true;
  2002. }
  2003.  
  2004. TreeOutline.prototype.reveal = function()
  2005. {
  2006.  
  2007. }
  2008.  
  2009. TreeOutline.prototype.select = function()
  2010. {
  2011.  
  2012. }
  2013.  
  2014.  
  2015. TreeOutline.prototype.revealAndSelect = function(omitFocus)
  2016. {
  2017.  
  2018. }
  2019.  
  2020.  
  2021. TreeOutline.prototype._startSearch = function(searchText)
  2022. {
  2023. if (!this.searchInputElement || !this.searchable)
  2024. return;
  2025.  
  2026. this._searching = true;
  2027.  
  2028. if (this.searchStarted)
  2029. this.searchStarted();
  2030.  
  2031. this.searchInputElement.value = searchText;
  2032.  
  2033. function focusSearchInput()
  2034. {
  2035. this.searchInputElement.focus();
  2036. }
  2037. window.setTimeout(focusSearchInput.bind(this), 0);
  2038. this._searchTextChanged();
  2039. this._boundSearchTextChanged = this._searchTextChanged.bind(this);
  2040. this.searchInputElement.addEventListener("paste", this._boundSearchTextChanged);
  2041. this.searchInputElement.addEventListener("cut", this._boundSearchTextChanged);
  2042. this.searchInputElement.addEventListener("keypress", this._boundSearchTextChanged);
  2043. this._boundSearchInputKeyDown = this._searchInputKeyDown.bind(this);
  2044. this.searchInputElement.addEventListener("keydown", this._boundSearchInputKeyDown);
  2045. this._boundSearchInputBlur = this._searchInputBlur.bind(this);
  2046. this.searchInputElement.addEventListener("blur", this._boundSearchInputBlur);
  2047. }
  2048.  
  2049. TreeOutline.prototype._searchTextChanged = function()
  2050. {
  2051. function updateSearch()
  2052. {
  2053. var nextSelectedElement = this._nextSearchMatch(this.searchInputElement.value, this.selectedTreeElement, false);
  2054. if (!nextSelectedElement)
  2055. nextSelectedElement = this._nextSearchMatch(this.searchInputElement.value, this.children[0], false);
  2056. this._showSearchMatchElement(nextSelectedElement);
  2057. }
  2058.  
  2059. window.setTimeout(updateSearch.bind(this), 0);
  2060. }
  2061.  
  2062. TreeOutline.prototype._showSearchMatchElement = function(treeElement)
  2063. {
  2064. this._currentSearchMatchElement = treeElement;
  2065. if (treeElement) {
  2066. this._childrenListNode.classList.add("search-match-found");
  2067. this._childrenListNode.classList.remove("search-match-not-found");
  2068. treeElement.revealAndSelect(true);
  2069. } else {
  2070. this._childrenListNode.classList.remove("search-match-found");
  2071. this._childrenListNode.classList.add("search-match-not-found");
  2072. }
  2073. }
  2074.  
  2075. TreeOutline.prototype._searchInputKeyDown = function(event)
  2076. {
  2077. if (event.shiftKey || event.metaKey || event.ctrlKey || event.altKey)
  2078. return;
  2079.  
  2080. var handled = false;
  2081. var nextSelectedElement;
  2082. if (event.keyIdentifier === "Down") {
  2083. nextSelectedElement = this._nextSearchMatch(this.searchInputElement.value, this.selectedTreeElement, true);
  2084. handled = true;
  2085. } else if (event.keyIdentifier === "Up") {
  2086. nextSelectedElement = this._previousSearchMatch(this.searchInputElement.value, this.selectedTreeElement);
  2087. handled = true;
  2088. } else if (event.keyCode === 27  ) {
  2089. this._searchFinished();
  2090. handled = true;
  2091. } else if (isEnterKey(event)) {
  2092. var lastSearchMatchElement = this._currentSearchMatchElement;
  2093. this._searchFinished();
  2094. lastSearchMatchElement.onenter();
  2095. handled = true;
  2096. }
  2097.  
  2098. if (nextSelectedElement)
  2099. this._showSearchMatchElement(nextSelectedElement);
  2100.  
  2101. if (handled)
  2102. event.consume(true);
  2103. else
  2104. window.setTimeout(this._boundSearchTextChanged, 0); 
  2105. }
  2106.  
  2107.  
  2108. TreeOutline.prototype._nextSearchMatch = function(searchText, startTreeElement, skipStartTreeElement)
  2109. {
  2110. var currentTreeElement = startTreeElement;
  2111. var skipCurrentTreeElement = skipStartTreeElement;
  2112. while (currentTreeElement && (skipCurrentTreeElement || !currentTreeElement.matchesSearchText || !currentTreeElement.matchesSearchText(searchText))) {
  2113. currentTreeElement = currentTreeElement.traverseNextTreeElement(true, null, true);
  2114. skipCurrentTreeElement = false;
  2115. }
  2116.  
  2117. return currentTreeElement;
  2118. }
  2119.  
  2120.  
  2121. TreeOutline.prototype._previousSearchMatch = function(searchText, startTreeElement)
  2122. {
  2123. var currentTreeElement = startTreeElement;
  2124. var skipCurrentTreeElement = true;
  2125. while (currentTreeElement && (skipCurrentTreeElement || !currentTreeElement.matchesSearchText || !currentTreeElement.matchesSearchText(searchText))) {
  2126. currentTreeElement = currentTreeElement.traversePreviousTreeElement(true, true);
  2127. skipCurrentTreeElement = false;
  2128. }
  2129.  
  2130. return currentTreeElement;
  2131. }
  2132.  
  2133. TreeOutline.prototype._searchInputBlur = function(event)
  2134. {
  2135. this._searchFinished();
  2136. }
  2137.  
  2138. TreeOutline.prototype._searchFinished = function()
  2139. {
  2140. if (!this._searching)
  2141. return;
  2142.  
  2143. delete this._searching;
  2144. this._childrenListNode.classList.remove("search-match-found");
  2145. this._childrenListNode.classList.remove("search-match-not-found");
  2146. delete this._currentSearchMatchElement;
  2147.  
  2148. this.searchInputElement.value = "";
  2149. this.searchInputElement.removeEventListener("paste", this._boundSearchTextChanged);
  2150. this.searchInputElement.removeEventListener("cut", this._boundSearchTextChanged);
  2151. delete this._boundSearchTextChanged;
  2152.  
  2153. this.searchInputElement.removeEventListener("keydown", this._boundSearchInputKeyDown);
  2154. delete this._boundSearchInputKeyDown;
  2155.  
  2156. this.searchInputElement.removeEventListener("blur", this._boundSearchInputBlur);
  2157. delete this._boundSearchInputBlur;
  2158.  
  2159. if (this.searchFinished)
  2160. this.searchFinished();
  2161.  
  2162. this.treeOutline._childrenListNode.focus();
  2163. }
  2164.  
  2165. TreeOutline.prototype.stopSearch = function()
  2166. {
  2167. this._searchFinished();
  2168. }
  2169.  
  2170.  
  2171. function TreeElement(title, representedObject, hasChildren)
  2172. {
  2173. this._title = title;
  2174. this.representedObject = (representedObject || {});
  2175.  
  2176. this._hidden = false;
  2177. this._selectable = true;
  2178. this.expanded = false;
  2179. this.selected = false;
  2180. this.hasChildren = hasChildren;
  2181. this.children = [];
  2182. this.treeOutline = null;
  2183. this.parent = null;
  2184. this.previousSibling = null;
  2185. this.nextSibling = null;
  2186. this._listItemNode = null;
  2187. }
  2188.  
  2189. TreeElement.prototype = {
  2190. arrowToggleWidth: 10,
  2191.  
  2192. get selectable() {
  2193. if (this._hidden)
  2194. return false;
  2195. return this._selectable;
  2196. },
  2197.  
  2198. set selectable(x) {
  2199. this._selectable = x;
  2200. },
  2201.  
  2202. get listItemElement() {
  2203. return this._listItemNode;
  2204. },
  2205.  
  2206. get childrenListElement() {
  2207. return this._childrenListNode;
  2208. },
  2209.  
  2210. get title() {
  2211. return this._title;
  2212. },
  2213.  
  2214. set title(x) {
  2215. this._title = x;
  2216. this._setListItemNodeContent();
  2217. },
  2218.  
  2219. get tooltip() {
  2220. return this._tooltip;
  2221. },
  2222.  
  2223. set tooltip(x) {
  2224. this._tooltip = x;
  2225. if (this._listItemNode)
  2226. this._listItemNode.title = x ? x : "";
  2227. },
  2228.  
  2229. get hasChildren() {
  2230. return this._hasChildren;
  2231. },
  2232.  
  2233. set hasChildren(x) {
  2234. if (this._hasChildren === x)
  2235. return;
  2236.  
  2237. this._hasChildren = x;
  2238.  
  2239. if (!this._listItemNode)
  2240. return;
  2241.  
  2242. if (x)
  2243. this._listItemNode.classList.add("parent");
  2244. else {
  2245. this._listItemNode.classList.remove("parent");
  2246. this.collapse();
  2247. }
  2248. },
  2249.  
  2250. get hidden() {
  2251. return this._hidden;
  2252. },
  2253.  
  2254. set hidden(x) {
  2255. if (this._hidden === x)
  2256. return;
  2257.  
  2258. this._hidden = x;
  2259.  
  2260. if (x) {
  2261. if (this._listItemNode)
  2262. this._listItemNode.classList.add("hidden");
  2263. if (this._childrenListNode)
  2264. this._childrenListNode.classList.add("hidden");
  2265. } else {
  2266. if (this._listItemNode)
  2267. this._listItemNode.classList.remove("hidden");
  2268. if (this._childrenListNode)
  2269. this._childrenListNode.classList.remove("hidden");
  2270. }
  2271. },
  2272.  
  2273. get shouldRefreshChildren() {
  2274. return this._shouldRefreshChildren;
  2275. },
  2276.  
  2277. set shouldRefreshChildren(x) {
  2278. this._shouldRefreshChildren = x;
  2279. if (x && this.expanded)
  2280. this.expand();
  2281. },
  2282.  
  2283. _setListItemNodeContent: function()
  2284. {
  2285. if (!this._listItemNode)
  2286. return;
  2287.  
  2288. if (typeof this._title === "string")
  2289. this._listItemNode.textContent = this._title;
  2290. else {
  2291. this._listItemNode.removeChildren();
  2292. if (this._title)
  2293. this._listItemNode.appendChild(this._title);
  2294. }
  2295. }
  2296. }
  2297.  
  2298. TreeElement.prototype.appendChild = TreeOutline.prototype.appendChild;
  2299. TreeElement.prototype.insertChild = TreeOutline.prototype.insertChild;
  2300. TreeElement.prototype.removeChild = TreeOutline.prototype.removeChild;
  2301. TreeElement.prototype.removeChildAtIndex = TreeOutline.prototype.removeChildAtIndex;
  2302. TreeElement.prototype.removeChildren = TreeOutline.prototype.removeChildren;
  2303.  
  2304. TreeElement.prototype._attach = function()
  2305. {
  2306. if (!this._listItemNode || this.parent._shouldRefreshChildren) {
  2307. if (this._listItemNode && this._listItemNode.parentNode)
  2308. this._listItemNode.parentNode.removeChild(this._listItemNode);
  2309.  
  2310. this._listItemNode = this.treeOutline._childrenListNode.ownerDocument.createElement("li");
  2311. this._listItemNode.treeElement = this;
  2312. this._setListItemNodeContent();
  2313. this._listItemNode.title = this._tooltip ? this._tooltip : "";
  2314.  
  2315. if (this.hidden)
  2316. this._listItemNode.classList.add("hidden");
  2317. if (this.hasChildren)
  2318. this._listItemNode.classList.add("parent");
  2319. if (this.expanded)
  2320. this._listItemNode.classList.add("expanded");
  2321. if (this.selected)
  2322. this._listItemNode.classList.add("selected");
  2323.  
  2324. this._listItemNode.addEventListener("mousedown", TreeElement.treeElementMouseDown, false);
  2325. this._listItemNode.addEventListener("click", TreeElement.treeElementToggled, false);
  2326. this._listItemNode.addEventListener("dblclick", TreeElement.treeElementDoubleClicked, false);
  2327.  
  2328. this.onattach();
  2329. }
  2330.  
  2331. var nextSibling = null;
  2332. if (this.nextSibling && this.nextSibling._listItemNode && this.nextSibling._listItemNode.parentNode === this.parent._childrenListNode)
  2333. nextSibling = this.nextSibling._listItemNode;
  2334. this.parent._childrenListNode.insertBefore(this._listItemNode, nextSibling);
  2335. if (this._childrenListNode)
  2336. this.parent._childrenListNode.insertBefore(this._childrenListNode, this._listItemNode.nextSibling);
  2337. if (this.selected)
  2338. this.select();
  2339. if (this.expanded)
  2340. this.expand();
  2341. }
  2342.  
  2343. TreeElement.prototype._detach = function()
  2344. {
  2345. if (this._listItemNode && this._listItemNode.parentNode)
  2346. this._listItemNode.parentNode.removeChild(this._listItemNode);
  2347. if (this._childrenListNode && this._childrenListNode.parentNode)
  2348. this._childrenListNode.parentNode.removeChild(this._childrenListNode);
  2349. }
  2350.  
  2351. TreeElement.treeElementMouseDown = function(event)
  2352. {
  2353. var element = event.currentTarget;
  2354. if (!element || !element.treeElement || !element.treeElement.selectable)
  2355. return;
  2356.  
  2357. if (element.treeElement.isEventWithinDisclosureTriangle(event))
  2358. return;
  2359.  
  2360. element.treeElement.selectOnMouseDown(event);
  2361. }
  2362.  
  2363. TreeElement.treeElementToggled = function(event)
  2364. {
  2365. var element = event.currentTarget;
  2366. if (!element || !element.treeElement)
  2367. return;
  2368.  
  2369. var toggleOnClick = element.treeElement.toggleOnClick && !element.treeElement.selectable;
  2370. var isInTriangle = element.treeElement.isEventWithinDisclosureTriangle(event);
  2371. if (!toggleOnClick && !isInTriangle)
  2372. return;
  2373.  
  2374. if (element.treeElement.expanded) {
  2375. if (event.altKey)
  2376. element.treeElement.collapseRecursively();
  2377. else
  2378. element.treeElement.collapse();
  2379. } else {
  2380. if (event.altKey)
  2381. element.treeElement.expandRecursively();
  2382. else
  2383. element.treeElement.expand();
  2384. }
  2385. event.consume();
  2386. }
  2387.  
  2388. TreeElement.treeElementDoubleClicked = function(event)
  2389. {
  2390. var element = event.currentTarget;
  2391. if (!element || !element.treeElement)
  2392. return;
  2393.  
  2394. var handled = element.treeElement.ondblclick.call(element.treeElement, event);
  2395. if (handled)
  2396. return;
  2397. if (element.treeElement.hasChildren && !element.treeElement.expanded)
  2398. element.treeElement.expand();
  2399. }
  2400.  
  2401. TreeElement.prototype.collapse = function()
  2402. {
  2403. if (this._listItemNode)
  2404. this._listItemNode.classList.remove("expanded");
  2405. if (this._childrenListNode)
  2406. this._childrenListNode.classList.remove("expanded");
  2407.  
  2408. this.expanded = false;
  2409.  
  2410. if (this.treeOutline)
  2411. this.treeOutline._expandedStateMap.put(this.representedObject, false);
  2412.  
  2413. this.oncollapse();
  2414. }
  2415.  
  2416. TreeElement.prototype.collapseRecursively = function()
  2417. {
  2418. var item = this;
  2419. while (item) {
  2420. if (item.expanded)
  2421. item.collapse();
  2422. item = item.traverseNextTreeElement(false, this, true);
  2423. }
  2424. }
  2425.  
  2426. TreeElement.prototype.expand = function()
  2427. {
  2428. if (!this.hasChildren || (this.expanded && !this._shouldRefreshChildren && this._childrenListNode))
  2429. return;
  2430.  
  2431.  
  2432.  
  2433.  
  2434.  
  2435. this.expanded = true;
  2436. if (this.treeOutline)
  2437. this.treeOutline._expandedStateMap.put(this.representedObject, true);
  2438.  
  2439. if (this.treeOutline && (!this._childrenListNode || this._shouldRefreshChildren)) {
  2440. if (this._childrenListNode && this._childrenListNode.parentNode)
  2441. this._childrenListNode.parentNode.removeChild(this._childrenListNode);
  2442.  
  2443. this._childrenListNode = this.treeOutline._childrenListNode.ownerDocument.createElement("ol");
  2444. this._childrenListNode.parentTreeElement = this;
  2445. this._childrenListNode.classList.add("children");
  2446.  
  2447. if (this.hidden)
  2448. this._childrenListNode.classList.add("hidden");
  2449.  
  2450. this.onpopulate();
  2451.  
  2452. for (var i = 0; i < this.children.length; ++i)
  2453. this.children[i]._attach();
  2454.  
  2455. delete this._shouldRefreshChildren;
  2456. }
  2457.  
  2458. if (this._listItemNode) {
  2459. this._listItemNode.classList.add("expanded");
  2460. if (this._childrenListNode && this._childrenListNode.parentNode != this._listItemNode.parentNode)
  2461. this.parent._childrenListNode.insertBefore(this._childrenListNode, this._listItemNode.nextSibling);
  2462. }
  2463.  
  2464. if (this._childrenListNode)
  2465. this._childrenListNode.classList.add("expanded");
  2466.  
  2467. this.onexpand();
  2468. }
  2469.  
  2470. TreeElement.prototype.expandRecursively = function(maxDepth)
  2471. {
  2472. var item = this;
  2473. var info = {};
  2474. var depth = 0;
  2475.  
  2476.  
  2477.  
  2478.  
  2479. if (isNaN(maxDepth))
  2480. maxDepth = 3;
  2481.  
  2482. while (item) {
  2483. if (depth < maxDepth)
  2484. item.expand();
  2485. item = item.traverseNextTreeElement(false, this, (depth >= maxDepth), info);
  2486. depth += info.depthChange;
  2487. }
  2488. }
  2489.  
  2490. TreeElement.prototype.hasAncestor = function(ancestor) {
  2491. if (!ancestor)
  2492. return false;
  2493.  
  2494. var currentNode = this.parent;
  2495. while (currentNode) {
  2496. if (ancestor === currentNode)
  2497. return true;
  2498. currentNode = currentNode.parent;
  2499. }
  2500.  
  2501. return false;
  2502. }
  2503.  
  2504. TreeElement.prototype.reveal = function()
  2505. {
  2506. var currentAncestor = this.parent;
  2507. while (currentAncestor && !currentAncestor.root) {
  2508. if (!currentAncestor.expanded)
  2509. currentAncestor.expand();
  2510. currentAncestor = currentAncestor.parent;
  2511. }
  2512.  
  2513. this.onreveal(this);
  2514. }
  2515.  
  2516. TreeElement.prototype.revealed = function()
  2517. {
  2518. var currentAncestor = this.parent;
  2519. while (currentAncestor && !currentAncestor.root) {
  2520. if (!currentAncestor.expanded)
  2521. return false;
  2522. currentAncestor = currentAncestor.parent;
  2523. }
  2524.  
  2525. return true;
  2526. }
  2527.  
  2528. TreeElement.prototype.selectOnMouseDown = function(event)
  2529. {
  2530. if (this.select(false, true))
  2531. event.consume(true);
  2532. }
  2533.  
  2534.  
  2535. TreeElement.prototype.select = function(omitFocus, selectedByUser)
  2536. {
  2537. if (!this.treeOutline || !this.selectable || this.selected)
  2538. return false;
  2539.  
  2540. if (this.treeOutline.selectedTreeElement)
  2541. this.treeOutline.selectedTreeElement.deselect();
  2542.  
  2543. this.selected = true;
  2544.  
  2545. if(!omitFocus)
  2546. this.treeOutline._childrenListNode.focus();
  2547.  
  2548.  
  2549. if (!this.treeOutline)
  2550. return false;
  2551. this.treeOutline.selectedTreeElement = this;
  2552. if (this._listItemNode)
  2553. this._listItemNode.classList.add("selected");
  2554.  
  2555. return this.onselect(selectedByUser);
  2556. }
  2557.  
  2558.  
  2559. TreeElement.prototype.revealAndSelect = function(omitFocus)
  2560. {
  2561. this.reveal();
  2562. this.select(omitFocus);
  2563. }
  2564.  
  2565.  
  2566. TreeElement.prototype.deselect = function(supressOnDeselect)
  2567. {
  2568. if (!this.treeOutline || this.treeOutline.selectedTreeElement !== this || !this.selected)
  2569. return false;
  2570.  
  2571. this.selected = false;
  2572. this.treeOutline.selectedTreeElement = null;
  2573. if (this._listItemNode)
  2574. this._listItemNode.classList.remove("selected");
  2575. return true;
  2576. }
  2577.  
  2578.  
  2579. TreeElement.prototype.onpopulate = function() { }
  2580. TreeElement.prototype.onenter = function() { }
  2581. TreeElement.prototype.ondelete = function() { }
  2582. TreeElement.prototype.onspace = function() { }
  2583. TreeElement.prototype.onattach = function() { }
  2584. TreeElement.prototype.onexpand = function() { }
  2585. TreeElement.prototype.oncollapse = function() { }
  2586. TreeElement.prototype.ondblclick = function() { }
  2587. TreeElement.prototype.onreveal = function() { }
  2588.  
  2589. TreeElement.prototype.onselect = function(selectedByUser) { }
  2590.  
  2591.  
  2592. TreeElement.prototype.traverseNextTreeElement = function(skipUnrevealed, stayWithin, dontPopulate, info)
  2593. {
  2594. if (!dontPopulate && this.hasChildren)
  2595. this.onpopulate();
  2596.  
  2597. if (info)
  2598. info.depthChange = 0;
  2599.  
  2600. var element = skipUnrevealed ? (this.revealed() ? this.children[0] : null) : this.children[0];
  2601. if (element && (!skipUnrevealed || (skipUnrevealed && this.expanded))) {
  2602. if (info)
  2603. info.depthChange = 1;
  2604. return element;
  2605. }
  2606.  
  2607. if (this === stayWithin)
  2608. return null;
  2609.  
  2610. element = skipUnrevealed ? (this.revealed() ? this.nextSibling : null) : this.nextSibling;
  2611. if (element)
  2612. return element;
  2613.  
  2614. element = this;
  2615. while (element && !element.root && !(skipUnrevealed ? (element.revealed() ? element.nextSibling : null) : element.nextSibling) && element.parent !== stayWithin) {
  2616. if (info)
  2617. info.depthChange -= 1;
  2618. element = element.parent;
  2619. }
  2620.  
  2621. if (!element)
  2622. return null;
  2623.  
  2624. return (skipUnrevealed ? (element.revealed() ? element.nextSibling : null) : element.nextSibling);
  2625. }
  2626.  
  2627.  
  2628. TreeElement.prototype.traversePreviousTreeElement = function(skipUnrevealed, dontPopulate)
  2629. {
  2630. var element = skipUnrevealed ? (this.revealed() ? this.previousSibling : null) : this.previousSibling;
  2631. if (!dontPopulate && element && element.hasChildren)
  2632. element.onpopulate();
  2633.  
  2634. while (element && (skipUnrevealed ? (element.revealed() && element.expanded ? element.children[element.children.length - 1] : null) : element.children[element.children.length - 1])) {
  2635. if (!dontPopulate && element.hasChildren)
  2636. element.onpopulate();
  2637. element = (skipUnrevealed ? (element.revealed() && element.expanded ? element.children[element.children.length - 1] : null) : element.children[element.children.length - 1]);
  2638. }
  2639.  
  2640. if (element)
  2641. return element;
  2642.  
  2643. if (!this.parent || this.parent.root)
  2644. return null;
  2645.  
  2646. return this.parent;
  2647. }
  2648.  
  2649. TreeElement.prototype.isEventWithinDisclosureTriangle = function(event)
  2650. {
  2651.  
  2652. var paddingLeftValue = window.getComputedStyle(this._listItemNode).getPropertyCSSValue("padding-left");
  2653. var computedLeftPadding = paddingLeftValue ? paddingLeftValue.getFloatValue(CSSPrimitiveValue.CSS_PX) : 0;
  2654. var left = this._listItemNode.totalOffsetLeft() + computedLeftPadding;
  2655. return event.pageX >= left && event.pageX <= left + this.arrowToggleWidth && this.hasChildren;
  2656. }
  2657.  
  2658.  
  2659.  
  2660.  
  2661.  
  2662. var WebInspector = {
  2663. _panelDescriptors: function()
  2664. {
  2665. this.panels = {};
  2666. WebInspector.inspectorView = new WebInspector.InspectorView();
  2667. var parentElement = document.getElementById("main");
  2668. WebInspector.inspectorView.show(parentElement);
  2669. WebInspector.inspectorView.addEventListener(WebInspector.InspectorView.Events.PanelSelected, this._panelSelected, this);
  2670.  
  2671. var elements = new WebInspector.ElementsPanelDescriptor();
  2672. var resources = new WebInspector.PanelDescriptor("resources", WebInspector.UIString("Resources"), "ResourcesPanel", "ResourcesPanel.js");
  2673. var network = new WebInspector.NetworkPanelDescriptor();
  2674. var scripts = new WebInspector.ScriptsPanelDescriptor();
  2675. var timeline = new WebInspector.TimelinePanelDescriptor();
  2676. var profiles = new WebInspector.PanelDescriptor("profiles", WebInspector.UIString("Profiles"), "ProfilesPanel", "ProfilesPanel.js");
  2677. var audits = new WebInspector.PanelDescriptor("audits", WebInspector.UIString("Audits"), "AuditsPanel", "AuditsPanel.js");
  2678. var console = new WebInspector.PanelDescriptor("console", WebInspector.UIString("Console"), "ConsolePanel");
  2679. var allDescriptors = [elements, resources, network, scripts, timeline, profiles, audits, console];
  2680.  
  2681. var panelDescriptors = [];
  2682. if (WebInspector.WorkerManager.isWorkerFrontend()) {
  2683. panelDescriptors.push(scripts);
  2684. panelDescriptors.push(timeline);
  2685. panelDescriptors.push(profiles);
  2686. panelDescriptors.push(console);
  2687. return panelDescriptors;
  2688. }
  2689. var hiddenPanels = InspectorFrontendHost.hiddenPanels();
  2690. for (var i = 0; i < allDescriptors.length; ++i) {
  2691. if (hiddenPanels.indexOf(allDescriptors[i].name()) === -1)
  2692. panelDescriptors.push(allDescriptors[i]);
  2693. }
  2694. return panelDescriptors;
  2695. },
  2696.  
  2697. _panelSelected: function()
  2698. {
  2699. this._toggleConsoleButton.setEnabled(WebInspector.inspectorView.currentPanel().name !== "console");
  2700. },
  2701.  
  2702. _createGlobalStatusBarItems: function()
  2703. {
  2704. var bottomStatusBarContainer = document.getElementById("bottom-status-bar-container");
  2705.  
  2706.  
  2707. var mainStatusBar = document.getElementById("main-status-bar");
  2708. mainStatusBar.insertBefore(this.dockController.element, bottomStatusBarContainer);
  2709.  
  2710. this._toggleConsoleButton = new WebInspector.StatusBarButton(WebInspector.UIString("Show console."), "console-status-bar-item");
  2711. this._toggleConsoleButton.addEventListener("click", this._toggleConsoleButtonClicked.bind(this), false);
  2712. mainStatusBar.insertBefore(this._toggleConsoleButton.element, bottomStatusBarContainer);
  2713.  
  2714. if (!WebInspector.WorkerManager.isWorkerFrontend()) {
  2715. this._nodeSearchButton = new WebInspector.StatusBarButton(WebInspector.UIString("Select an element in the page to inspect it."), "node-search-status-bar-item");
  2716. this._nodeSearchButton.addEventListener("click", this.toggleSearchingForNode, this);
  2717. mainStatusBar.insertBefore(this._nodeSearchButton.element, bottomStatusBarContainer);
  2718. }
  2719.  
  2720. mainStatusBar.appendChild(this.settingsController.statusBarItem);
  2721. },
  2722.  
  2723. _toggleConsoleButtonClicked: function()
  2724. {
  2725. if (!this._toggleConsoleButton.enabled())
  2726. return;
  2727.  
  2728. this._toggleConsoleButton.toggled = !this._toggleConsoleButton.toggled;
  2729.  
  2730. var animationType = window.event && window.event.shiftKey ? WebInspector.Drawer.AnimationType.Slow : WebInspector.Drawer.AnimationType.Normal;
  2731. if (this._toggleConsoleButton.toggled) {
  2732. this._toggleConsoleButton.title = WebInspector.UIString("Hide console.");
  2733. this.drawer.show(this.consoleView, animationType);
  2734. this._consoleWasShown = true;
  2735. } else {
  2736. this._toggleConsoleButton.title = WebInspector.UIString("Show console.");
  2737. this.drawer.hide(animationType);
  2738. delete this._consoleWasShown;
  2739. }
  2740. },
  2741.  
  2742.  
  2743. showViewInDrawer: function(statusBarElement, view, onclose)
  2744. {
  2745. this._toggleConsoleButton.title = WebInspector.UIString("Hide console.");
  2746. this._toggleConsoleButton.toggled = false;
  2747. this._closePreviousDrawerView();
  2748.  
  2749. var drawerStatusBarHeader = document.createElement("div");
  2750. drawerStatusBarHeader.className = "drawer-header status-bar-item";
  2751. drawerStatusBarHeader.appendChild(statusBarElement);
  2752. drawerStatusBarHeader.onclose = onclose;
  2753.  
  2754. var closeButton = drawerStatusBarHeader.createChild("span");
  2755. closeButton.textContent = WebInspector.UIString("\u00D7");
  2756. closeButton.addStyleClass("drawer-header-close-button");
  2757. closeButton.addEventListener("click", this.closeViewInDrawer.bind(this), false);
  2758.  
  2759. document.getElementById("panel-status-bar").firstElementChild.appendChild(drawerStatusBarHeader);
  2760. this._drawerStatusBarHeader = drawerStatusBarHeader;
  2761. this.drawer.show(view, WebInspector.Drawer.AnimationType.Immediately);
  2762. },
  2763.  
  2764. closeViewInDrawer: function()
  2765. {
  2766. if (this._drawerStatusBarHeader) {
  2767. this._closePreviousDrawerView();
  2768.  
  2769.  
  2770. if (!this._consoleWasShown)
  2771. this.drawer.hide(WebInspector.Drawer.AnimationType.Immediately);
  2772. else
  2773. this._toggleConsoleButtonClicked();
  2774. }
  2775. },
  2776.  
  2777. _closePreviousDrawerView: function()
  2778. {
  2779. if (this._drawerStatusBarHeader) {
  2780. this._drawerStatusBarHeader.parentElement.removeChild(this._drawerStatusBarHeader);
  2781. if (this._drawerStatusBarHeader.onclose)
  2782. this._drawerStatusBarHeader.onclose();
  2783. delete this._drawerStatusBarHeader;
  2784. }
  2785. },
  2786.  
  2787. _updateErrorAndWarningCounts: function()
  2788. {
  2789. var errorWarningElement = document.getElementById("error-warning-count");
  2790. if (!errorWarningElement)
  2791. return;
  2792.  
  2793. var errors = WebInspector.console.errors;
  2794. var warnings = WebInspector.console.warnings;
  2795. if (!errors && !warnings) {
  2796. errorWarningElement.addStyleClass("hidden");
  2797. return;
  2798. }
  2799.  
  2800. errorWarningElement.removeStyleClass("hidden");
  2801.  
  2802. errorWarningElement.removeChildren();
  2803.  
  2804. if (errors) {
  2805. var errorImageElement = document.createElement("img");
  2806. errorImageElement.id = "error-count-img";
  2807. errorWarningElement.appendChild(errorImageElement);
  2808. var errorElement = document.createElement("span");
  2809. errorElement.id = "error-count";
  2810. errorElement.textContent = errors;
  2811. errorWarningElement.appendChild(errorElement);
  2812. }
  2813.  
  2814. if (warnings) {
  2815. var warningsImageElement = document.createElement("img");
  2816. warningsImageElement.id = "warning-count-img";
  2817. errorWarningElement.appendChild(warningsImageElement);
  2818. var warningsElement = document.createElement("span");
  2819. warningsElement.id = "warning-count";
  2820. warningsElement.textContent = warnings;
  2821. errorWarningElement.appendChild(warningsElement);
  2822. }
  2823.  
  2824. if (errors) {
  2825. if (warnings) {
  2826. if (errors == 1) {
  2827. if (warnings == 1)
  2828. errorWarningElement.title = WebInspector.UIString("%d error, %d warning", errors, warnings);
  2829. else
  2830. errorWarningElement.title = WebInspector.UIString("%d error, %d warnings", errors, warnings);
  2831. } else if (warnings == 1)
  2832. errorWarningElement.title = WebInspector.UIString("%d errors, %d warning", errors, warnings);
  2833. else
  2834. errorWarningElement.title = WebInspector.UIString("%d errors, %d warnings", errors, warnings);
  2835. } else if (errors == 1)
  2836. errorWarningElement.title = WebInspector.UIString("%d error", errors);
  2837. else
  2838. errorWarningElement.title = WebInspector.UIString("%d errors", errors);
  2839. } else if (warnings == 1)
  2840. errorWarningElement.title = WebInspector.UIString("%d warning", warnings);
  2841. else if (warnings)
  2842. errorWarningElement.title = WebInspector.UIString("%d warnings", warnings);
  2843. else
  2844. errorWarningElement.title = null;
  2845. },
  2846.  
  2847. get inspectedPageDomain()
  2848. {
  2849. var parsedURL = WebInspector.inspectedPageURL && WebInspector.inspectedPageURL.asParsedURL();
  2850. return parsedURL ? parsedURL.host : "";
  2851. },
  2852.  
  2853. _initializeCapability: function(name, callback, error, result)
  2854. {
  2855. Capabilities[name] = result;
  2856. if (callback)
  2857. callback();
  2858. },
  2859.  
  2860. _zoomIn: function()
  2861. {
  2862. this._zoomLevel = Math.min(this._zoomLevel + 1, WebInspector.Zoom.Table.length - WebInspector.Zoom.DefaultOffset - 1);
  2863. this._requestZoom();
  2864. },
  2865.  
  2866. _zoomOut: function()
  2867. {
  2868. this._zoomLevel = Math.max(this._zoomLevel - 1, -WebInspector.Zoom.DefaultOffset);
  2869. this._requestZoom();
  2870. },
  2871.  
  2872. _resetZoom: function()
  2873. {
  2874. this._zoomLevel = 0;
  2875. this._requestZoom();
  2876. },
  2877.  
  2878. _requestZoom: function()
  2879. {
  2880. WebInspector.settings.zoomLevel.set(this._zoomLevel);
  2881.  
  2882. var index = this._zoomLevel + WebInspector.Zoom.DefaultOffset;
  2883. index = Math.min(WebInspector.Zoom.Table.length - 1, index);
  2884. index = Math.max(0, index);
  2885. InspectorFrontendHost.setZoomFactor(WebInspector.Zoom.Table[index]);
  2886. },
  2887.  
  2888. toggleSearchingForNode: function()
  2889. {
  2890. var enabled = !this._nodeSearchButton.toggled;
  2891.  
  2892. function callback(error)
  2893. {
  2894. if (!error)
  2895. this._nodeSearchButton.toggled = enabled;
  2896. }
  2897. WebInspector.domAgent.setInspectModeEnabled(enabled, callback.bind(this));
  2898. },
  2899.  
  2900. _profilesLinkifier: function(title)
  2901. {
  2902. var profileStringMatches = WebInspector.ProfileURLRegExp.exec(title);
  2903. if (profileStringMatches) {
  2904. var profilesPanel =   WebInspector.panel("profiles");
  2905. title = WebInspector.ProfilesPanel._instance.displayTitleForProfileLink(profileStringMatches[2], profileStringMatches[1]);
  2906. }
  2907. return title;
  2908. },
  2909.  
  2910. _debuggerPaused: function()
  2911. {
  2912.  
  2913. WebInspector.panel("scripts");
  2914. }
  2915. }
  2916.  
  2917. WebInspector.Events = {
  2918. InspectorLoaded: "InspectorLoaded",
  2919. InspectorClosing: "InspectorClosing"
  2920. }
  2921.  
  2922. {(function parseQueryParameters()
  2923. {
  2924. WebInspector.queryParamsObject = {};
  2925. var queryParams = window.location.search;
  2926. if (!queryParams)
  2927. return;
  2928. var params = queryParams.substring(1).split("&");
  2929. for (var i = 0; i < params.length; ++i) {
  2930. var pair = params[i].split("=");
  2931. WebInspector.queryParamsObject[pair[0]] = pair[1];
  2932. }
  2933. })();}
  2934.  
  2935. WebInspector.loaded = function()
  2936. {
  2937. InspectorBackend.loadFromJSONIfNeeded("../Inspector.json");
  2938. WebInspector.dockController = new WebInspector.DockController();
  2939.  
  2940. if (WebInspector.WorkerManager.isDedicatedWorkerFrontend()) {
  2941.  
  2942. WebInspector.doLoadedDone();
  2943. return;
  2944. }
  2945.  
  2946. var ws;
  2947. if ("ws" in WebInspector.queryParamsObject)
  2948. ws = "ws://" + WebInspector.queryParamsObject.ws;
  2949. else if ("page" in WebInspector.queryParamsObject) {
  2950. var page = WebInspector.queryParamsObject.page;
  2951. var host = "host" in WebInspector.queryParamsObject ? WebInspector.queryParamsObject.host : window.location.host;
  2952. ws = "ws://" + host + "/devtools/page/" + page;
  2953. }
  2954.  
  2955. if (ws) {
  2956. WebInspector.socket = new WebSocket(ws);
  2957. WebInspector.socket.onmessage = function(message) { InspectorBackend.dispatch(message.data); }
  2958. WebInspector.socket.onerror = function(error) { console.error(error); }
  2959. WebInspector.socket.onopen = function() {
  2960. InspectorFrontendHost.sendMessageToBackend = WebInspector.socket.send.bind(WebInspector.socket);
  2961. WebInspector.doLoadedDone();
  2962. }
  2963. WebInspector.socket.onclose = function() {
  2964. if (!WebInspector.socket._detachReason)
  2965. (new WebInspector.RemoteDebuggingTerminatedScreen("websocket_closed")).showModal();
  2966. }
  2967. return;
  2968. }
  2969.  
  2970. WebInspector.doLoadedDone();
  2971.  
  2972.  
  2973. if (InspectorFrontendHost.isStub) {
  2974. InspectorFrontendAPI.dispatchQueryParameters();
  2975. WebInspector._doLoadedDoneWithCapabilities();
  2976. }
  2977. }
  2978.  
  2979. WebInspector.doLoadedDone = function()
  2980. {
  2981.  
  2982. WebInspector.installPortStyles();
  2983. if (WebInspector.socket)
  2984. document.body.addStyleClass("remote");
  2985.  
  2986. if (WebInspector.queryParamsObject.toolbarColor && WebInspector.queryParamsObject.textColor)
  2987. WebInspector.setToolbarColors(WebInspector.queryParamsObject.toolbarColor, WebInspector.queryParamsObject.textColor);
  2988.  
  2989. InspectorFrontendHost.loaded();
  2990. WebInspector.WorkerManager.loaded();
  2991.  
  2992. DebuggerAgent.causesRecompilation(WebInspector._initializeCapability.bind(WebInspector, "debuggerCausesRecompilation", null));
  2993. DebuggerAgent.supportsSeparateScriptCompilationAndExecution(WebInspector._initializeCapability.bind(WebInspector, "separateScriptCompilationAndExecutionEnabled", null));
  2994. ProfilerAgent.causesRecompilation(WebInspector._initializeCapability.bind(WebInspector, "profilerCausesRecompilation", null));
  2995. ProfilerAgent.isSampling(WebInspector._initializeCapability.bind(WebInspector, "samplingCPUProfiler", null));
  2996. ProfilerAgent.hasHeapProfiler(WebInspector._initializeCapability.bind(WebInspector, "heapProfilerPresent", null));
  2997. TimelineAgent.supportsFrameInstrumentation(WebInspector._initializeCapability.bind(WebInspector, "timelineSupportsFrameInstrumentation", null));
  2998. TimelineAgent.canMonitorMainThread(WebInspector._initializeCapability.bind(WebInspector, "timelineCanMonitorMainThread", null));
  2999. PageAgent.canShowFPSCounter(WebInspector._initializeCapability.bind(WebInspector, "canShowFPSCounter", null));
  3000. PageAgent.canOverrideDeviceMetrics(WebInspector._initializeCapability.bind(WebInspector, "canOverrideDeviceMetrics", null));
  3001. PageAgent.canOverrideGeolocation(WebInspector._initializeCapability.bind(WebInspector, "canOverrideGeolocation", null));
  3002. PageAgent.canOverrideDeviceOrientation(WebInspector._initializeCapability.bind(WebInspector, "canOverrideDeviceOrientation", WebInspector._doLoadedDoneWithCapabilities.bind(WebInspector)));
  3003. }
  3004.  
  3005. WebInspector._doLoadedDoneWithCapabilities = function()
  3006. {
  3007. WebInspector.shortcutsScreen = new WebInspector.ShortcutsScreen();
  3008. this._registerShortcuts();
  3009.  
  3010.  
  3011. WebInspector.shortcutsScreen.section(WebInspector.UIString("Console"));
  3012. WebInspector.shortcutsScreen.section(WebInspector.UIString("Elements Panel"));
  3013.  
  3014. var panelDescriptors = this._panelDescriptors();
  3015. for (var i = 0; i < panelDescriptors.length; ++i)
  3016. panelDescriptors[i].registerShortcuts();
  3017.  
  3018. this.console = new WebInspector.ConsoleModel();
  3019. this.console.addEventListener(WebInspector.ConsoleModel.Events.ConsoleCleared, this._updateErrorAndWarningCounts, this);
  3020. this.console.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, this._updateErrorAndWarningCounts, this);
  3021. this.console.addEventListener(WebInspector.ConsoleModel.Events.RepeatCountUpdated, this._updateErrorAndWarningCounts, this);
  3022.  
  3023. WebInspector.CSSCompletions.requestCSSNameCompletions();
  3024.  
  3025. this.drawer = new WebInspector.Drawer();
  3026.  
  3027. this.networkManager = new WebInspector.NetworkManager();
  3028. this.resourceTreeModel = new WebInspector.ResourceTreeModel(this.networkManager);
  3029. this.debuggerModel = new WebInspector.DebuggerModel();
  3030. this.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerPaused, this._debuggerPaused, this);
  3031. this.networkLog = new WebInspector.NetworkLog();
  3032. this.domAgent = new WebInspector.DOMAgent();
  3033. this.runtimeModel = new WebInspector.RuntimeModel(this.resourceTreeModel);
  3034.  
  3035. this.consoleView = new WebInspector.ConsoleView(WebInspector.WorkerManager.isWorkerFrontend());
  3036.  
  3037. InspectorBackend.registerInspectorDispatcher(this);
  3038.  
  3039. this.cssModel = new WebInspector.CSSStyleModel();
  3040. this.timelineManager = new WebInspector.TimelineManager();
  3041. this.userAgentSupport = new WebInspector.UserAgentSupport();
  3042.  
  3043. this.searchController = new WebInspector.SearchController();
  3044. this.advancedSearchController = new WebInspector.AdvancedSearchController();
  3045. this.settingsController = new WebInspector.SettingsController();
  3046.  
  3047. this.domBreakpointsSidebarPane = new WebInspector.DOMBreakpointsSidebarPane();
  3048.  
  3049. this._zoomLevel = WebInspector.settings.zoomLevel.get();
  3050. if (this._zoomLevel)
  3051. this._requestZoom();
  3052.  
  3053. var autoselectPanel = WebInspector.UIString("a panel chosen automatically");
  3054. var openAnchorLocationSetting = WebInspector.settings.createSetting("openLinkHandler", autoselectPanel);
  3055. this.openAnchorLocationRegistry = new WebInspector.HandlerRegistry(openAnchorLocationSetting);
  3056. this.openAnchorLocationRegistry.registerHandler(autoselectPanel, function() { return false; });
  3057.  
  3058. this.networkWorkspaceProvider = new WebInspector.NetworkWorkspaceProvider();
  3059. this.workspace = new WebInspector.Workspace();
  3060. this.workspace.addProject("network", this.networkWorkspaceProvider);
  3061. this.workspaceController = new WebInspector.WorkspaceController(this.workspace);
  3062.  
  3063. this.breakpointManager = new WebInspector.BreakpointManager(WebInspector.settings.breakpoints, this.debuggerModel, this.workspace);
  3064.  
  3065. this.scriptSnippetModel = new WebInspector.ScriptSnippetModel(this.workspace, this.networkWorkspaceProvider);
  3066. new WebInspector.DebuggerScriptMapping(this.workspace, this.networkWorkspaceProvider);
  3067. this.styleContentBinding = new WebInspector.StyleContentBinding(this.cssModel);
  3068. new WebInspector.NetworkUISourceCodeProvider(this.workspace, this.networkWorkspaceProvider);
  3069. new WebInspector.StylesSourceMapping(this.workspace);
  3070. if (WebInspector.experimentsSettings.sass.isEnabled())
  3071. new WebInspector.SASSSourceMapping(this.workspace, this.networkWorkspaceProvider);
  3072.  
  3073. new WebInspector.PresentationConsoleMessageHelper(this.workspace);
  3074.  
  3075. this._createGlobalStatusBarItems();
  3076.  
  3077. this.toolbar = new WebInspector.Toolbar();
  3078. WebInspector.startBatchUpdate();
  3079. for (var i = 0; i < panelDescriptors.length; ++i)
  3080. WebInspector.inspectorView.addPanel(panelDescriptors[i]);
  3081. WebInspector.endBatchUpdate();
  3082.  
  3083. this.addMainEventListeners(document);
  3084. WebInspector.registerLinkifierPlugin(this._profilesLinkifier.bind(this));
  3085.  
  3086. window.addEventListener("resize", this.windowResize.bind(this), true);
  3087.  
  3088. var errorWarningCount = document.getElementById("error-warning-count");
  3089. errorWarningCount.addEventListener("click", this.showConsole.bind(this), false);
  3090. this._updateErrorAndWarningCounts();
  3091.  
  3092. this.extensionServer.initExtensions();
  3093.  
  3094. this.console.enableAgent();
  3095.  
  3096. function showInitialPanel()
  3097. {
  3098. if (!WebInspector.inspectorView.currentPanel())
  3099. WebInspector.showPanel(WebInspector.settings.lastActivePanel.get());
  3100. }
  3101.  
  3102. InspectorAgent.enable(showInitialPanel);
  3103. this.databaseModel = new WebInspector.DatabaseModel();
  3104. this.domStorageModel = new WebInspector.DOMStorageModel();
  3105.  
  3106. if (!Capabilities.profilerCausesRecompilation || WebInspector.settings.profilerEnabled.get())
  3107. ProfilerAgent.enable();
  3108.  
  3109. if (WebInspector.settings.showPaintRects.get())
  3110. PageAgent.setShowPaintRects(true);
  3111.  
  3112. if (WebInspector.settings.javaScriptDisabled.get())
  3113. PageAgent.setScriptExecutionDisabled(true);
  3114.  
  3115. if (WebInspector.settings.showFPSCounter.get())
  3116. PageAgent.setShowFPSCounter(true);
  3117.  
  3118. this.domAgent._emulateTouchEventsChanged();
  3119.  
  3120. WebInspector.WorkerManager.loadCompleted();
  3121. InspectorFrontendAPI.loadCompleted();
  3122.  
  3123. WebInspector.notifications.dispatchEventToListeners(WebInspector.Events.InspectorLoaded);
  3124. }
  3125.  
  3126. var windowLoaded = function()
  3127. {
  3128. var localizedStringsURL = InspectorFrontendHost.localizedStringsURL();
  3129. if (localizedStringsURL) {
  3130. var localizedStringsScriptElement = document.createElement("script");
  3131. localizedStringsScriptElement.addEventListener("load", WebInspector.loaded.bind(WebInspector), false);
  3132. localizedStringsScriptElement.type = "text/javascript";
  3133. localizedStringsScriptElement.src = localizedStringsURL;
  3134. document.head.appendChild(localizedStringsScriptElement);
  3135. } else
  3136. WebInspector.loaded();
  3137.  
  3138. window.removeEventListener("DOMContentLoaded", windowLoaded, false);
  3139. delete windowLoaded;
  3140. };
  3141.  
  3142. window.addEventListener("DOMContentLoaded", windowLoaded, false);
  3143.  
  3144.  
  3145.  
  3146.  
  3147.  
  3148.  
  3149.  
  3150. var messagesToDispatch = [];
  3151.  
  3152. WebInspector.dispatchQueueIsEmpty = function() {
  3153. return messagesToDispatch.length == 0;
  3154. }
  3155.  
  3156. WebInspector.dispatch = function(message) {
  3157. messagesToDispatch.push(message);
  3158. setTimeout(function() {
  3159. InspectorBackend.dispatch(messagesToDispatch.shift());
  3160. }, 0);
  3161. }
  3162.  
  3163. WebInspector.windowResize = function(event)
  3164. {
  3165. if (WebInspector.inspectorView)
  3166. WebInspector.inspectorView.doResize();
  3167. if (WebInspector.drawer)
  3168. WebInspector.drawer.resize();
  3169. if (WebInspector.toolbar)
  3170. WebInspector.toolbar.resize();
  3171. if (WebInspector.settingsController)
  3172. WebInspector.settingsController.resize();
  3173. }
  3174.  
  3175. WebInspector.setDockingUnavailable = function(unavailable)
  3176. {
  3177. if (this.dockController)
  3178. this.dockController.setDockingUnavailable(unavailable);
  3179. }
  3180.  
  3181. WebInspector.close = function(event)
  3182. {
  3183. if (this._isClosing)
  3184. return;
  3185. this._isClosing = true;
  3186. this.notifications.dispatchEventToListeners(WebInspector.Events.InspectorClosing);
  3187. InspectorFrontendHost.closeWindow();
  3188. }
  3189.  
  3190. WebInspector.documentClick = function(event)
  3191. {
  3192. var anchor = event.target.enclosingNodeOrSelfWithNodeName("a");
  3193. if (!anchor || (anchor.target === "_blank" && !WebInspector.ProfileURLRegExp.exec(anchor.href)))
  3194. return;
  3195.  
  3196.  
  3197. event.consume(true);
  3198.  
  3199. function followLink()
  3200. {
  3201. if (WebInspector.isBeingEdited(event.target) || WebInspector._showAnchorLocation(anchor))
  3202. return;
  3203.  
  3204. const profileMatch = WebInspector.ProfileURLRegExp.exec(anchor.href);
  3205. if (profileMatch) {
  3206. WebInspector.showProfileForURL(anchor.href);
  3207. return;
  3208. }
  3209.  
  3210. var parsedURL = anchor.href.asParsedURL();
  3211. if (parsedURL && parsedURL.scheme === "webkit-link-action") {
  3212. if (parsedURL.host === "show-panel") {
  3213. var panel = parsedURL.path.substring(1);
  3214. if (WebInspector.panel(panel))
  3215. WebInspector.showPanel(panel);
  3216. }
  3217. return;
  3218. }
  3219.  
  3220. InspectorFrontendHost.openInNewTab(anchor.href);
  3221. }
  3222.  
  3223. if (WebInspector.followLinkTimeout)
  3224. clearTimeout(WebInspector.followLinkTimeout);
  3225.  
  3226. if (anchor.preventFollowOnDoubleClick) {
  3227.  
  3228.  
  3229. if (event.detail === 1)
  3230. WebInspector.followLinkTimeout = setTimeout(followLink, 333);
  3231. return;
  3232. }
  3233.  
  3234. followLink();
  3235. }
  3236.  
  3237. WebInspector.openResource = function(resourceURL, inResourcesPanel)
  3238. {
  3239. var resource = WebInspector.resourceForURL(resourceURL);
  3240. if (inResourcesPanel && resource)
  3241. WebInspector.showPanel("resources").showResource(resource);
  3242. else
  3243. InspectorFrontendHost.openInNewTab(resourceURL);
  3244. }
  3245.  
  3246. WebInspector._registerShortcuts = function()
  3247. {
  3248. var shortcut = WebInspector.KeyboardShortcut;
  3249. var section = WebInspector.shortcutsScreen.section(WebInspector.UIString("All Panels"));
  3250. var keys = [
  3251. shortcut.makeDescriptor("[", shortcut.Modifiers.CtrlOrMeta),
  3252. shortcut.makeDescriptor("]", shortcut.Modifiers.CtrlOrMeta)
  3253. ];
  3254. section.addRelatedKeys(keys, WebInspector.UIString("Go to the panel to the left/right"));
  3255.  
  3256. var keys = [
  3257. shortcut.makeDescriptor("[", shortcut.Modifiers.CtrlOrMeta | shortcut.Modifiers.Alt),
  3258. shortcut.makeDescriptor("]", shortcut.Modifiers.CtrlOrMeta | shortcut.Modifiers.Alt)
  3259. ];
  3260. section.addRelatedKeys(keys, WebInspector.UIString("Go back/forward in panel history"));
  3261.  
  3262. section.addKey(shortcut.makeDescriptor(shortcut.Keys.Esc), WebInspector.UIString("Toggle console"));
  3263. section.addKey(shortcut.makeDescriptor("f", shortcut.Modifiers.CtrlOrMeta), WebInspector.UIString("Search"));
  3264.  
  3265. var advancedSearchShortcut = WebInspector.AdvancedSearchController.createShortcut();
  3266. section.addKey(advancedSearchShortcut, WebInspector.UIString("Search across all sources"));
  3267.  
  3268. var openResourceShortcut = WebInspector.KeyboardShortcut.makeDescriptor("o", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta);
  3269. section.addKey(openResourceShortcut, WebInspector.UIString("Go to source"));
  3270.  
  3271. if (WebInspector.isMac()) {
  3272. keys = [
  3273. shortcut.makeDescriptor("g", shortcut.Modifiers.Meta),
  3274. shortcut.makeDescriptor("g", shortcut.Modifiers.Meta | shortcut.Modifiers.Shift)
  3275. ];
  3276. section.addRelatedKeys(keys, WebInspector.UIString("Find next/previous"));
  3277. }
  3278.  
  3279. var goToShortcut = WebInspector.GoToLineDialog.createShortcut();
  3280. section.addKey(goToShortcut, WebInspector.UIString("Go to line"));
  3281. }
  3282.  
  3283.  
  3284. WebInspector.documentKeyDown = function(event)
  3285. {
  3286. const helpKey = WebInspector.isMac() ? "U+003F" : "U+00BF"; 
  3287.  
  3288. if (event.keyIdentifier === "F1" ||
  3289. (event.keyIdentifier === helpKey && event.shiftKey && (!WebInspector.isBeingEdited(event.target) || event.metaKey))) {
  3290. this.settingsController.showSettingsScreen(WebInspector.SettingsScreen.Tabs.Shortcuts);
  3291. event.consume(true);
  3292. return;
  3293. }
  3294.  
  3295. if (WebInspector.currentFocusElement() && WebInspector.currentFocusElement().handleKeyEvent) {
  3296. WebInspector.currentFocusElement().handleKeyEvent(event);
  3297. if (event.handled) {
  3298. event.consume(true);
  3299. return;
  3300. }
  3301. }
  3302.  
  3303. if (WebInspector.inspectorView.currentPanel()) {
  3304. WebInspector.inspectorView.currentPanel().handleShortcut(event);
  3305. if (event.handled) {
  3306. event.consume(true);
  3307. return;
  3308. }
  3309. }
  3310.  
  3311. if (WebInspector.searchController.handleShortcut(event))
  3312. return;
  3313. if (WebInspector.advancedSearchController.handleShortcut(event))
  3314. return;
  3315.  
  3316. switch (event.keyIdentifier) {
  3317. case "U+004F": 
  3318. if (!event.shiftKey && !event.altKey && WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event)) {
  3319. WebInspector.showPanel("scripts").showGoToSourceDialog();
  3320. event.consume(true);
  3321. }
  3322. break;
  3323. case "U+0052": 
  3324. if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event)) {
  3325. PageAgent.reload(event.shiftKey);
  3326. event.consume(true);
  3327. }
  3328. break;
  3329. case "F5":
  3330. if (!WebInspector.isMac()) {
  3331. PageAgent.reload(event.ctrlKey || event.shiftKey);
  3332. event.consume(true);
  3333. }
  3334. break;
  3335. }
  3336.  
  3337. var isValidZoomShortcut = WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event) &&
  3338. !event.altKey &&
  3339. !InspectorFrontendHost.isStub;
  3340. switch (event.keyCode) {
  3341. case 107: 
  3342. case 187: 
  3343. if (isValidZoomShortcut) {
  3344. WebInspector._zoomIn();
  3345. event.consume(true);
  3346. }
  3347. break;
  3348. case 109: 
  3349. case 189: 
  3350. if (isValidZoomShortcut) {
  3351. WebInspector._zoomOut();
  3352. event.consume(true);
  3353. }
  3354. break;
  3355. case 48: 
  3356.  
  3357. if (isValidZoomShortcut && !event.shiftKey) {
  3358. WebInspector._resetZoom();
  3359. event.consume(true);
  3360. }
  3361. break;
  3362. }
  3363.  
  3364.  
  3365.  
  3366. if (event.keyIdentifier === "U+0043") { 
  3367. if (WebInspector.isMac())
  3368. var isNodeSearchKey = event.metaKey && !event.ctrlKey && !event.altKey && event.shiftKey;
  3369. else
  3370. var isNodeSearchKey = event.ctrlKey && !event.metaKey && !event.altKey && event.shiftKey;
  3371.  
  3372. if (isNodeSearchKey) {
  3373. this.toggleSearchingForNode();
  3374. event.consume(true);
  3375. return;
  3376. }
  3377. return;
  3378. }
  3379. }
  3380.  
  3381. WebInspector.postDocumentKeyDown = function(event)
  3382. {
  3383. if (event.handled)
  3384. return;
  3385.  
  3386. if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code) {
  3387.  
  3388. if (!this._toggleConsoleButton.toggled && WebInspector.drawer.visible)
  3389. this.closeViewInDrawer();
  3390. else
  3391. this._toggleConsoleButtonClicked();
  3392. }
  3393. }
  3394.  
  3395. WebInspector.documentCanCopy = function(event)
  3396. {
  3397. if (WebInspector.inspectorView.currentPanel() && WebInspector.inspectorView.currentPanel().handleCopyEvent)
  3398. event.preventDefault();
  3399. }
  3400.  
  3401. WebInspector.documentCopy = function(event)
  3402. {
  3403. if (WebInspector.inspectorView.currentPanel() && WebInspector.inspectorView.currentPanel().handleCopyEvent)
  3404. WebInspector.inspectorView.currentPanel().handleCopyEvent(event);
  3405. WebInspector.documentCopyEventFired(event);
  3406. }
  3407.  
  3408. WebInspector.documentCopyEventFired = function(event)
  3409. {
  3410. }
  3411.  
  3412. WebInspector.contextMenuEventFired = function(event)
  3413. {
  3414. if (event.handled || event.target.hasStyleClass("popup-glasspane"))
  3415. event.preventDefault();
  3416. }
  3417.  
  3418. WebInspector.showConsole = function()
  3419. {
  3420. if (WebInspector._toggleConsoleButton && !WebInspector._toggleConsoleButton.toggled) {
  3421. if (WebInspector.drawer.visible)
  3422. this._closePreviousDrawerView();
  3423. WebInspector._toggleConsoleButtonClicked();
  3424. }
  3425. }
  3426.  
  3427. WebInspector.showPanel = function(panel)
  3428. {
  3429. return WebInspector.inspectorView.showPanel(panel);
  3430. }
  3431.  
  3432. WebInspector.panel = function(panel)
  3433. {
  3434. return WebInspector.inspectorView.panel(panel);
  3435. }
  3436.  
  3437. WebInspector.bringToFront = function()
  3438. {
  3439. InspectorFrontendHost.bringToFront();
  3440. }
  3441.  
  3442.  
  3443. WebInspector.log = function(message, messageLevel, showConsole)
  3444. {
  3445.  
  3446. var self = this;
  3447.  
  3448.  
  3449. function isLogAvailable()
  3450. {
  3451. return WebInspector.ConsoleMessage && WebInspector.RemoteObject && self.console;
  3452. }
  3453.  
  3454.  
  3455. function flushQueue()
  3456. {
  3457. var queued = WebInspector.log.queued;
  3458. if (!queued)
  3459. return;
  3460.  
  3461. for (var i = 0; i < queued.length; ++i)
  3462. logMessage(queued[i]);
  3463.  
  3464. delete WebInspector.log.queued;
  3465. }
  3466.  
  3467.  
  3468.  
  3469. function flushQueueIfAvailable()
  3470. {
  3471. if (!isLogAvailable())
  3472. return;
  3473.  
  3474. clearInterval(WebInspector.log.interval);
  3475. delete WebInspector.log.interval;
  3476.  
  3477. flushQueue();
  3478. }
  3479.  
  3480.  
  3481. function logMessage(message)
  3482. {
  3483.  
  3484. var msg = WebInspector.ConsoleMessage.create(
  3485. WebInspector.ConsoleMessage.MessageSource.Other,
  3486. messageLevel || WebInspector.ConsoleMessage.MessageLevel.Debug,
  3487. message);
  3488.  
  3489. self.console.addMessage(msg);
  3490. if (showConsole)
  3491. WebInspector.showConsole();
  3492. }
  3493.  
  3494.  
  3495. if (!isLogAvailable()) {
  3496. if (!WebInspector.log.queued)
  3497. WebInspector.log.queued = [];
  3498.  
  3499. WebInspector.log.queued.push(message);
  3500.  
  3501. if (!WebInspector.log.interval)
  3502. WebInspector.log.interval = setInterval(flushQueueIfAvailable, 1000);
  3503.  
  3504. return;
  3505. }
  3506.  
  3507.  
  3508. flushQueue();
  3509.  
  3510.  
  3511. logMessage(message);
  3512. }
  3513.  
  3514. WebInspector.showErrorMessage = function(error)
  3515. {
  3516. WebInspector.log(error, WebInspector.ConsoleMessage.MessageLevel.Error, true);
  3517. }
  3518.  
  3519.  
  3520. WebInspector.inspect = function(payload, hints)
  3521. {
  3522. var object = WebInspector.RemoteObject.fromPayload(payload);
  3523. if (object.subtype === "node") {
  3524. function callback(nodeId)
  3525. {
  3526. WebInspector._updateFocusedNode(nodeId);
  3527. object.release();
  3528. }
  3529. object.pushNodeToFrontend(callback);
  3530. return;
  3531. }
  3532.  
  3533. if (hints.databaseId)
  3534. WebInspector.showPanel("resources").selectDatabase(WebInspector.databaseModel.databaseForId(hints.databaseId));
  3535. else if (hints.domStorageId)
  3536. WebInspector.showPanel("resources").selectDOMStorage(WebInspector.domStorageModel.storageForId(hints.domStorageId));
  3537.  
  3538. object.release();
  3539. }
  3540.  
  3541.  
  3542. WebInspector.detached = function(reason)
  3543. {
  3544. WebInspector.socket._detachReason = reason;
  3545. (new WebInspector.RemoteDebuggingTerminatedScreen(reason)).showModal();
  3546. }
  3547.  
  3548. WebInspector._updateFocusedNode = function(nodeId)
  3549. {
  3550. if (WebInspector._nodeSearchButton.toggled) {
  3551. InspectorFrontendHost.bringToFront();
  3552. WebInspector._nodeSearchButton.toggled = false;
  3553. }
  3554. WebInspector.showPanel("elements").revealAndSelectNode(nodeId);
  3555. }
  3556.  
  3557. WebInspector._showAnchorLocation = function(anchor)
  3558. {
  3559. if (WebInspector.openAnchorLocationRegistry.dispatch({ url: anchor.href, lineNumber: anchor.lineNumber}))
  3560. return true;
  3561. var preferredPanel = this.panels[anchor.preferredPanel];
  3562. if (preferredPanel && WebInspector._showAnchorLocationInPanel(anchor, preferredPanel))
  3563. return true;
  3564. if (WebInspector._showAnchorLocationInPanel(anchor, this.panel("scripts")))
  3565. return true;
  3566. if (WebInspector._showAnchorLocationInPanel(anchor, this.panel("resources")))
  3567. return true;
  3568. if (WebInspector._showAnchorLocationInPanel(anchor, this.panel("network")))
  3569. return true;
  3570. return false;
  3571. }
  3572.  
  3573. WebInspector._showAnchorLocationInPanel = function(anchor, panel)
  3574. {
  3575. if (!panel || !panel.canShowAnchorLocation(anchor))
  3576. return false;
  3577.  
  3578.  
  3579. if (anchor.hasStyleClass("webkit-html-external-link")) {
  3580. anchor.removeStyleClass("webkit-html-external-link");
  3581. anchor.addStyleClass("webkit-html-resource-link");
  3582. }
  3583.  
  3584. WebInspector.inspectorView.showPanelForAnchorNavigation(panel);
  3585. panel.showAnchorLocation(anchor);
  3586. return true;
  3587. }
  3588.  
  3589. WebInspector.showProfileForURL = function(url)
  3590. {
  3591. WebInspector.showPanel("profiles").showProfileForURL(url);
  3592. }
  3593.  
  3594. WebInspector.evaluateInConsole = function(expression, showResultOnly)
  3595. {
  3596. this.showConsole();
  3597. this.consoleView.evaluateUsingTextPrompt(expression, showResultOnly);
  3598. }
  3599.  
  3600. WebInspector.addMainEventListeners = function(doc)
  3601. {
  3602. doc.addEventListener("keydown", this.documentKeyDown.bind(this), true);
  3603. doc.addEventListener("keydown", this.postDocumentKeyDown.bind(this), false);
  3604. doc.addEventListener("beforecopy", this.documentCanCopy.bind(this), true);
  3605. doc.addEventListener("copy", this.documentCopy.bind(this), true);
  3606. doc.addEventListener("contextmenu", this.contextMenuEventFired.bind(this), true);
  3607. doc.addEventListener("click", this.documentClick.bind(this), true);
  3608. }
  3609.  
  3610. WebInspector.ProfileURLRegExp = /webkit-profile:\/\/(.+)\/(.+)#([0-9]+)/;
  3611.  
  3612. WebInspector.Zoom = {
  3613. Table: [0.25, 0.33, 0.5, 0.66, 0.75, 0.9, 1, 1.1, 1.25, 1.5, 1.75, 2, 2.5, 3, 4, 5],
  3614. DefaultOffset: 6
  3615. }
  3616.  
  3617.  
  3618.  
  3619.  
  3620.  
  3621. WebInspector.UIString = function(string, vararg)
  3622. {
  3623. if (Preferences.localizeUI) {
  3624. if (window.localizedStrings && string in window.localizedStrings)
  3625. string = window.localizedStrings[string];
  3626. else {
  3627. if (!(string in WebInspector._missingLocalizedStrings)) {
  3628. console.warn("Localized string \"" + string + "\" not found.");
  3629. WebInspector._missingLocalizedStrings[string] = true;
  3630. }
  3631.  
  3632. if (Preferences.showMissingLocalizedStrings)
  3633. string += " (not localized)";
  3634. }
  3635. }
  3636. return String.vsprintf(string, Array.prototype.slice.call(arguments, 1));
  3637. }
  3638.  
  3639. WebInspector._missingLocalizedStrings = {};
  3640.  
  3641.  
  3642.  
  3643.  
  3644.  
  3645.  
  3646. WebInspector.installDragHandle = function(element, elementDragStart, elementDrag, elementDragEnd, cursor)
  3647. {
  3648. element.addEventListener("mousedown", WebInspector._elementDragStart.bind(WebInspector, elementDragStart, elementDrag, elementDragEnd, cursor), false);
  3649. }
  3650.  
  3651.  
  3652. WebInspector._elementDragStart = function(elementDragStart, elementDrag, elementDragEnd, cursor, event)
  3653. {
  3654.  
  3655. if (event.button || (WebInspector.isMac() && event.ctrlKey))
  3656. return;
  3657.  
  3658. if (WebInspector._elementDraggingEventListener)
  3659. return;
  3660.  
  3661. if (elementDragStart && !elementDragStart(event))
  3662. return;
  3663.  
  3664. if (WebInspector._elementDraggingGlassPane) {
  3665. WebInspector._elementDraggingGlassPane.dispose();
  3666. delete WebInspector._elementDraggingGlassPane;
  3667. }
  3668.  
  3669. var targetDocument = event.target.ownerDocument;
  3670.  
  3671. WebInspector._elementDraggingEventListener = elementDrag;
  3672. WebInspector._elementEndDraggingEventListener = elementDragEnd;
  3673. WebInspector._mouseOutWhileDraggingTargetDocument = targetDocument;
  3674.  
  3675. targetDocument.addEventListener("mousemove", WebInspector._elementDraggingEventListener, true);
  3676. targetDocument.addEventListener("mouseup", WebInspector._elementDragEnd, true);
  3677. targetDocument.addEventListener("mouseout", WebInspector._mouseOutWhileDragging, true);
  3678.  
  3679. targetDocument.body.style.cursor = cursor;
  3680.  
  3681. event.preventDefault();
  3682. }
  3683.  
  3684. WebInspector._mouseOutWhileDragging = function()
  3685. {
  3686. WebInspector._unregisterMouseOutWhileDragging();
  3687. WebInspector._elementDraggingGlassPane = new WebInspector.GlassPane();
  3688. }
  3689.  
  3690. WebInspector._unregisterMouseOutWhileDragging = function()
  3691. {
  3692. if (!WebInspector._mouseOutWhileDraggingTargetDocument)
  3693. return;
  3694. WebInspector._mouseOutWhileDraggingTargetDocument.removeEventListener("mouseout", WebInspector._mouseOutWhileDragging, true);
  3695. delete WebInspector._mouseOutWhileDraggingTargetDocument;
  3696. }
  3697.  
  3698. WebInspector._elementDragEnd = function(event)
  3699. {
  3700. var targetDocument = event.target.ownerDocument;
  3701. targetDocument.removeEventListener("mousemove", WebInspector._elementDraggingEventListener, true);
  3702. targetDocument.removeEventListener("mouseup", WebInspector._elementDragEnd, true);
  3703. WebInspector._unregisterMouseOutWhileDragging();
  3704.  
  3705. targetDocument.body.style.removeProperty("cursor");
  3706.  
  3707. if (WebInspector._elementDraggingGlassPane)
  3708. WebInspector._elementDraggingGlassPane.dispose();
  3709.  
  3710. var elementDragEnd = WebInspector._elementEndDraggingEventListener;
  3711.  
  3712. delete WebInspector._elementDraggingGlassPane;
  3713. delete WebInspector._elementDraggingEventListener;
  3714. delete WebInspector._elementEndDraggingEventListener;
  3715.  
  3716. event.preventDefault();
  3717. if (elementDragEnd)
  3718. elementDragEnd(event);
  3719. }
  3720.  
  3721.  
  3722. WebInspector.GlassPane = function()
  3723. {
  3724. this.element = document.createElement("div");
  3725. this.element.style.cssText = "position:absolute;top:0;bottom:0;left:0;right:0;background-color:transparent;z-index:1000;";
  3726. this.element.id = "glass-pane-for-drag";
  3727. document.body.appendChild(this.element);
  3728. }
  3729.  
  3730. WebInspector.GlassPane.prototype = {
  3731. dispose: function()
  3732. {
  3733. if (this.element.parentElement)
  3734. this.element.parentElement.removeChild(this.element);
  3735. }
  3736. }
  3737.  
  3738. WebInspector.animateStyle = function(animations, duration, callback)
  3739. {
  3740. var interval;
  3741. var complete = 0;
  3742. var hasCompleted = false;
  3743.  
  3744. const intervalDuration = (1000 / 30); 
  3745. const animationsLength = animations.length;
  3746. const propertyUnit = {opacity: ""};
  3747. const defaultUnit = "px";
  3748.  
  3749. function cubicInOut(t, b, c, d)
  3750. {
  3751. if ((t/=d/2) < 1) return c/2*t*t*t + b;
  3752. return c/2*((t-=2)*t*t + 2) + b;
  3753. }
  3754.  
  3755.  
  3756. for (var i = 0; i < animationsLength; ++i) {
  3757. var animation = animations[i];
  3758. var element = null, start = null, end = null, key = null;
  3759. for (key in animation) {
  3760. if (key === "element")
  3761. element = animation[key];
  3762. else if (key === "start")
  3763. start = animation[key];
  3764. else if (key === "end")
  3765. end = animation[key];
  3766. }
  3767.  
  3768. if (!element || !end)
  3769. continue;
  3770.  
  3771. if (!start) {
  3772. var computedStyle = element.ownerDocument.defaultView.getComputedStyle(element);
  3773. start = {};
  3774. for (key in end)
  3775. start[key] = parseInt(computedStyle.getPropertyValue(key), 10);
  3776. animation.start = start;
  3777. } else
  3778. for (key in start)
  3779. element.style.setProperty(key, start[key] + (key in propertyUnit ? propertyUnit[key] : defaultUnit));
  3780. }
  3781.  
  3782. function animateLoop()
  3783. {
  3784. if (hasCompleted)
  3785. return;
  3786.  
  3787.  
  3788. complete += intervalDuration;
  3789. var next = complete + intervalDuration;
  3790.  
  3791.  
  3792. for (var i = 0; i < animationsLength; ++i) {
  3793. var animation = animations[i];
  3794. var element = animation.element;
  3795. var start = animation.start;
  3796. var end = animation.end;
  3797. if (!element || !end)
  3798. continue;
  3799.  
  3800. var style = element.style;
  3801. for (key in end) {
  3802. var endValue = end[key];
  3803. if (next < duration) {
  3804. var startValue = start[key];
  3805. var newValue = cubicInOut(complete, startValue, endValue - startValue, duration);
  3806. style.setProperty(key, newValue + (key in propertyUnit ? propertyUnit[key] : defaultUnit));
  3807. } else
  3808. style.setProperty(key, endValue + (key in propertyUnit ? propertyUnit[key] : defaultUnit));
  3809. }
  3810. }
  3811.  
  3812.  
  3813. if (complete >= duration) {
  3814. hasCompleted = true;
  3815. clearInterval(interval);
  3816. if (callback)
  3817. callback();
  3818. }
  3819. }
  3820.  
  3821. function forceComplete()
  3822. {
  3823. if (hasCompleted)
  3824. return;
  3825.  
  3826. complete = duration;
  3827. animateLoop();
  3828. }
  3829.  
  3830. function cancel()
  3831. {
  3832. hasCompleted = true;
  3833. clearInterval(interval);
  3834. }
  3835.  
  3836. interval = setInterval(animateLoop, intervalDuration);
  3837. return {
  3838. cancel: cancel,
  3839. forceComplete: forceComplete
  3840. };
  3841. }
  3842.  
  3843. WebInspector.isBeingEdited = function(element)
  3844. {
  3845. if (element.hasStyleClass("text-prompt") || element.nodeName === "INPUT")
  3846. return true;
  3847.  
  3848. if (!WebInspector.__editingCount)
  3849. return false;
  3850.  
  3851. while (element) {
  3852. if (element.__editing)
  3853. return true;
  3854. element = element.parentElement;
  3855. }
  3856. return false;
  3857. }
  3858.  
  3859. WebInspector.markBeingEdited = function(element, value)
  3860. {
  3861. if (value) {
  3862. if (element.__editing)
  3863. return false;
  3864. element.__editing = true;
  3865. WebInspector.__editingCount = (WebInspector.__editingCount || 0) + 1;
  3866. } else {
  3867. if (!element.__editing)
  3868. return false;
  3869. delete element.__editing;
  3870. --WebInspector.__editingCount;
  3871. }
  3872. return true;
  3873. }
  3874.  
  3875.  
  3876. WebInspector.EditingConfig = function(commitHandler, cancelHandler, context)
  3877. {
  3878. this.commitHandler = commitHandler;
  3879. this.cancelHandler = cancelHandler
  3880. this.context = context;
  3881.  
  3882.  
  3883. this.pasteHandler;
  3884.  
  3885.  
  3886. this.multiline;
  3887.  
  3888.  
  3889. this.customFinishHandler;
  3890. }
  3891.  
  3892. WebInspector.EditingConfig.prototype = {
  3893. setPasteHandler: function(pasteHandler)
  3894. {
  3895. this.pasteHandler = pasteHandler;
  3896. },
  3897.  
  3898. setMultiline: function(multiline)
  3899. {
  3900. this.multiline = multiline;
  3901. },
  3902.  
  3903. setCustomFinishHandler: function(customFinishHandler)
  3904. {
  3905. this.customFinishHandler = customFinishHandler;
  3906. }
  3907. }
  3908.  
  3909. WebInspector.CSSNumberRegex = /^(-?(?:\d+(?:\.\d+)?|\.\d+))$/;
  3910.  
  3911. WebInspector.StyleValueDelimiters = " \xA0\t\n\"':;,/()";
  3912.  
  3913.  
  3914.  
  3915. WebInspector._valueModificationDirection = function(event)
  3916. {
  3917. var direction = null;
  3918. if (event.type === "mousewheel") {
  3919. if (event.wheelDeltaY > 0)
  3920. direction = "Up";
  3921. else if (event.wheelDeltaY < 0)
  3922. direction = "Down";
  3923. } else {
  3924. if (event.keyIdentifier === "Up" || event.keyIdentifier === "PageUp")
  3925. direction = "Up";
  3926. else if (event.keyIdentifier === "Down" || event.keyIdentifier === "PageDown")
  3927. direction = "Down";        
  3928. }
  3929. return direction;
  3930. }
  3931.  
  3932.  
  3933. WebInspector._modifiedHexValue = function(hexString, event)
  3934. {
  3935. var direction = WebInspector._valueModificationDirection(event);
  3936. if (!direction)
  3937. return hexString;
  3938.  
  3939. var number = parseInt(hexString, 16);
  3940. if (isNaN(number) || !isFinite(number))
  3941. return hexString;
  3942.  
  3943. var maxValue = Math.pow(16, hexString.length) - 1;
  3944. var arrowKeyOrMouseWheelEvent = (event.keyIdentifier === "Up" || event.keyIdentifier === "Down" || event.type === "mousewheel");
  3945. var delta;
  3946.  
  3947. if (arrowKeyOrMouseWheelEvent)
  3948. delta = (direction === "Up") ? 1 : -1;
  3949. else
  3950. delta = (event.keyIdentifier === "PageUp") ? 16 : -16;
  3951.  
  3952. if (event.shiftKey)
  3953. delta *= 16;
  3954.  
  3955. var result = number + delta;
  3956. if (result < 0)
  3957. result = 0; 
  3958. else if (result > maxValue)
  3959. return hexString;
  3960.  
  3961.  
  3962. var resultString = result.toString(16).toUpperCase();
  3963. for (var i = 0, lengthDelta = hexString.length - resultString.length; i < lengthDelta; ++i)
  3964. resultString = "0" + resultString;
  3965. return resultString;
  3966. }
  3967.  
  3968.  
  3969. WebInspector._modifiedFloatNumber = function(number, event)
  3970. {
  3971. var direction = WebInspector._valueModificationDirection(event);
  3972. if (!direction)
  3973. return number;
  3974.  
  3975. var arrowKeyOrMouseWheelEvent = (event.keyIdentifier === "Up" || event.keyIdentifier === "Down" || event.type === "mousewheel");
  3976.  
  3977.  
  3978.  
  3979. var changeAmount = 1;
  3980. if (event.shiftKey && !arrowKeyOrMouseWheelEvent)
  3981. changeAmount = 100;
  3982. else if (event.shiftKey || !arrowKeyOrMouseWheelEvent)
  3983. changeAmount = 10;
  3984. else if (event.altKey)
  3985. changeAmount = 0.1;
  3986.  
  3987. if (direction === "Down")
  3988. changeAmount *= -1;
  3989.  
  3990.  
  3991.  
  3992. var result = Number((number + changeAmount).toFixed(6));
  3993. if (!String(result).match(WebInspector.CSSNumberRegex))
  3994. return null;
  3995.  
  3996. return result;
  3997. }
  3998.  
  3999.  
  4000. WebInspector.handleElementValueModifications = function(event, element, finishHandler, suggestionHandler, customNumberHandler)
  4001. {
  4002. var arrowKeyOrMouseWheelEvent = (event.keyIdentifier === "Up" || event.keyIdentifier === "Down" || event.type === "mousewheel");
  4003. var pageKeyPressed = (event.keyIdentifier === "PageUp" || event.keyIdentifier === "PageDown");
  4004. if (!arrowKeyOrMouseWheelEvent && !pageKeyPressed)
  4005. return false;
  4006.  
  4007. var selection = window.getSelection();
  4008. if (!selection.rangeCount)
  4009. return false;
  4010.  
  4011. var selectionRange = selection.getRangeAt(0);
  4012. if (!selectionRange.commonAncestorContainer.isSelfOrDescendant(element))
  4013. return false;
  4014.  
  4015. var originalValue = element.textContent;
  4016. var wordRange = selectionRange.startContainer.rangeOfWord(selectionRange.startOffset, WebInspector.StyleValueDelimiters, element);
  4017. var wordString = wordRange.toString();
  4018.  
  4019. if (suggestionHandler && suggestionHandler(wordString))
  4020. return false;
  4021.  
  4022. var replacementString;
  4023. var prefix, suffix, number;
  4024.  
  4025. var matches;
  4026. matches = /(.*#)([\da-fA-F]+)(.*)/.exec(wordString);
  4027. if (matches && matches.length) {
  4028. prefix = matches[1];
  4029. suffix = matches[3];
  4030. number = WebInspector._modifiedHexValue(matches[2], event);
  4031.  
  4032. if (customNumberHandler)
  4033. number = customNumberHandler(number);
  4034.  
  4035. replacementString = prefix + number + suffix;
  4036. } else {
  4037. matches = /(.*?)(-?(?:\d+(?:\.\d+)?|\.\d+))(.*)/.exec(wordString);
  4038. if (matches && matches.length) {
  4039. prefix = matches[1];
  4040. suffix = matches[3];
  4041. number = WebInspector._modifiedFloatNumber(parseFloat(matches[2]), event);
  4042.  
  4043.  
  4044. if (number === null)                
  4045. return false;
  4046.  
  4047. if (customNumberHandler)
  4048. number = customNumberHandler(number);
  4049.  
  4050. replacementString = prefix + number + suffix;
  4051. }
  4052. }
  4053.  
  4054. if (replacementString) {
  4055. var replacementTextNode = document.createTextNode(replacementString);
  4056.  
  4057. wordRange.deleteContents();
  4058. wordRange.insertNode(replacementTextNode);
  4059.  
  4060. var finalSelectionRange = document.createRange();
  4061. finalSelectionRange.setStart(replacementTextNode, 0);
  4062. finalSelectionRange.setEnd(replacementTextNode, replacementString.length);
  4063.  
  4064. selection.removeAllRanges();
  4065. selection.addRange(finalSelectionRange);
  4066.  
  4067. event.handled = true;
  4068. event.preventDefault();
  4069.  
  4070. if (finishHandler)
  4071. finishHandler(originalValue, replacementString);
  4072.  
  4073. return true;
  4074. }
  4075. return false;
  4076. }
  4077.  
  4078.  
  4079. WebInspector.startEditing = function(element, config)
  4080. {
  4081. if (!WebInspector.markBeingEdited(element, true))
  4082. return null;
  4083.  
  4084. config = config || new WebInspector.EditingConfig(function() {}, function() {});
  4085. var committedCallback = config.commitHandler;
  4086. var cancelledCallback = config.cancelHandler;
  4087. var pasteCallback = config.pasteHandler;
  4088. var context = config.context;
  4089. var oldText = getContent(element);
  4090. var moveDirection = "";
  4091.  
  4092. element.addStyleClass("editing");
  4093.  
  4094. var oldTabIndex = element.getAttribute("tabIndex");
  4095. if (typeof oldTabIndex !== "number" || oldTabIndex < 0)
  4096. element.tabIndex = 0;
  4097.  
  4098. function blurEventListener() {
  4099. editingCommitted.call(element);
  4100. }
  4101.  
  4102. function getContent(element) {
  4103. if (element.tagName === "INPUT" && element.type === "text")
  4104. return element.value;
  4105. else
  4106. return element.textContent;
  4107. }
  4108.  
  4109.  
  4110. function cleanUpAfterEditing()
  4111. {
  4112. WebInspector.markBeingEdited(element, false);
  4113.  
  4114. this.removeStyleClass("editing");
  4115.  
  4116. if (typeof oldTabIndex !== "number")
  4117. element.removeAttribute("tabIndex");
  4118. else
  4119. this.tabIndex = oldTabIndex;
  4120. this.scrollTop = 0;
  4121. this.scrollLeft = 0;
  4122.  
  4123. element.removeEventListener("blur", blurEventListener, false);
  4124. element.removeEventListener("keydown", keyDownEventListener, true);
  4125. if (pasteCallback)
  4126. element.removeEventListener("paste", pasteEventListener, true);
  4127.  
  4128. WebInspector.restoreFocusFromElement(element);
  4129. }
  4130.  
  4131.  
  4132. function editingCancelled()
  4133. {
  4134. if (this.tagName === "INPUT" && this.type === "text")
  4135. this.value = oldText;
  4136. else
  4137. this.textContent = oldText;
  4138.  
  4139. cleanUpAfterEditing.call(this);
  4140.  
  4141. cancelledCallback(this, context);
  4142. }
  4143.  
  4144.  
  4145. function editingCommitted()
  4146. {
  4147. cleanUpAfterEditing.call(this);
  4148.  
  4149. committedCallback(this, getContent(this), oldText, context, moveDirection);
  4150. }
  4151.  
  4152. function defaultFinishHandler(event)
  4153. {
  4154. var isMetaOrCtrl = WebInspector.isMac() ?
  4155. event.metaKey && !event.shiftKey && !event.ctrlKey && !event.altKey :
  4156. event.ctrlKey && !event.shiftKey && !event.metaKey && !event.altKey;
  4157. if (isEnterKey(event) && (event.isMetaOrCtrlForTest || !config.multiline || isMetaOrCtrl))
  4158. return "commit";
  4159. else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code || event.keyIdentifier === "U+001B")
  4160. return "cancel";
  4161. else if (event.keyIdentifier === "U+0009") 
  4162. return "move-" + (event.shiftKey ? "backward" : "forward");
  4163. }
  4164.  
  4165. function handleEditingResult(result, event)
  4166. {
  4167. if (result === "commit") {
  4168. editingCommitted.call(element);
  4169. event.consume(true);
  4170. } else if (result === "cancel") {
  4171. editingCancelled.call(element);
  4172. event.consume(true);
  4173. } else if (result && result.startsWith("move-")) {
  4174. moveDirection = result.substring(5);
  4175. if (event.keyIdentifier !== "U+0009")
  4176. blurEventListener();
  4177. }
  4178. }
  4179.  
  4180. function pasteEventListener(event)
  4181. {
  4182. var result = pasteCallback(event);
  4183. handleEditingResult(result, event);
  4184. }
  4185.  
  4186. function keyDownEventListener(event)
  4187. {
  4188. var handler = config.customFinishHandler || defaultFinishHandler;
  4189. var result = handler(event);
  4190. handleEditingResult(result, event);
  4191. }
  4192.  
  4193. element.addEventListener("blur", blurEventListener, false);
  4194. element.addEventListener("keydown", keyDownEventListener, true);
  4195. if (pasteCallback)
  4196. element.addEventListener("paste", pasteEventListener, true);
  4197.  
  4198. WebInspector.setCurrentFocusElement(element);
  4199. return {
  4200. cancel: editingCancelled.bind(element),
  4201. commit: editingCommitted.bind(element)
  4202. };
  4203. }
  4204.  
  4205.  
  4206. Number.secondsToString = function(seconds, higherResolution)
  4207. {
  4208. if (!isFinite(seconds))
  4209. return "-";
  4210.  
  4211. if (seconds === 0)
  4212. return "0";
  4213.  
  4214. var ms = seconds * 1000;
  4215. if (higherResolution && ms < 1000)
  4216. return WebInspector.UIString("%.3f\u2009ms", ms);
  4217. else if (ms < 1000)
  4218. return WebInspector.UIString("%.0f\u2009ms", ms);
  4219.  
  4220. if (seconds < 60)
  4221. return WebInspector.UIString("%.2f\u2009s", seconds);
  4222.  
  4223. var minutes = seconds / 60;
  4224. if (minutes < 60)
  4225. return WebInspector.UIString("%.1f\u2009min", minutes);
  4226.  
  4227. var hours = minutes / 60;
  4228. if (hours < 24)
  4229. return WebInspector.UIString("%.1f\u2009hrs", hours);
  4230.  
  4231. var days = hours / 24;
  4232. return WebInspector.UIString("%.1f\u2009days", days);
  4233. }
  4234.  
  4235.  
  4236. Number.bytesToString = function(bytes)
  4237. {
  4238. if (bytes < 1024)
  4239. return WebInspector.UIString("%.0f\u2009B", bytes);
  4240.  
  4241. var kilobytes = bytes / 1024;
  4242. if (kilobytes < 100)
  4243. return WebInspector.UIString("%.1f\u2009KB", kilobytes);
  4244. if (kilobytes < 1024)
  4245. return WebInspector.UIString("%.0f\u2009KB", kilobytes);
  4246.  
  4247. var megabytes = kilobytes / 1024;
  4248. if (megabytes < 100)
  4249. return WebInspector.UIString("%.1f\u2009MB", megabytes);
  4250. else
  4251. return WebInspector.UIString("%.0f\u2009MB", megabytes);
  4252. }
  4253.  
  4254. Number.withThousandsSeparator = function(num)
  4255. {
  4256. var str = num + "";
  4257. var re = /(\d+)(\d{3})/;
  4258. while (str.match(re))
  4259. str = str.replace(re, "$1\u2009$2"); 
  4260. return str;
  4261. }
  4262.  
  4263. WebInspector.useLowerCaseMenuTitles = function()
  4264. {
  4265. return WebInspector.platform() === "windows" && Preferences.useLowerCaseMenuTitlesOnWindows;
  4266. }
  4267.  
  4268. WebInspector.formatLocalized = function(format, substitutions, formatters, initialValue, append)
  4269. {
  4270. return String.format(WebInspector.UIString(format), substitutions, formatters, initialValue, append);
  4271. }
  4272.  
  4273. WebInspector.openLinkExternallyLabel = function()
  4274. {
  4275. return WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Open link in new tab" : "Open Link in New Tab");
  4276. }
  4277.  
  4278. WebInspector.copyLinkAddressLabel = function()
  4279. {
  4280. return WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy link address" : "Copy Link Address");
  4281. }
  4282.  
  4283. WebInspector.platform = function()
  4284. {
  4285. if (!WebInspector._platform)
  4286. WebInspector._platform = InspectorFrontendHost.platform();
  4287. return WebInspector._platform;
  4288. }
  4289.  
  4290. WebInspector.isMac = function()
  4291. {
  4292. if (typeof WebInspector._isMac === "undefined")
  4293. WebInspector._isMac = WebInspector.platform() === "mac";
  4294.  
  4295. return WebInspector._isMac;
  4296. }
  4297.  
  4298. WebInspector.isWin = function()
  4299. {
  4300. if (typeof WebInspector._isWin === "undefined")
  4301. WebInspector._isWin = WebInspector.platform() === "windows";
  4302.  
  4303. return WebInspector._isWin;
  4304. }
  4305.  
  4306. WebInspector.PlatformFlavor = {
  4307. WindowsVista: "windows-vista",
  4308. MacTiger: "mac-tiger",
  4309. MacLeopard: "mac-leopard",
  4310. MacSnowLeopard: "mac-snowleopard",
  4311. MacLion: "mac-lion",
  4312. MacMountainLion: "mac-mountain-lion"
  4313. }
  4314.  
  4315. WebInspector.platformFlavor = function()
  4316. {
  4317. function detectFlavor()
  4318. {
  4319. const userAgent = navigator.userAgent;
  4320.  
  4321. if (WebInspector.platform() === "windows") {
  4322. var match = userAgent.match(/Windows NT (\d+)\.(?:\d+)/);
  4323. if (match && match[1] >= 6)
  4324. return WebInspector.PlatformFlavor.WindowsVista;
  4325. return null;
  4326. } else if (WebInspector.platform() === "mac") {
  4327. var match = userAgent.match(/Mac OS X\s*(?:(\d+)_(\d+))?/);
  4328. if (!match || match[1] != 10)
  4329. return WebInspector.PlatformFlavor.MacSnowLeopard;
  4330. switch (Number(match[2])) {
  4331. case 4:
  4332. return WebInspector.PlatformFlavor.MacTiger;
  4333. case 5:
  4334. return WebInspector.PlatformFlavor.MacLeopard;
  4335. case 6:
  4336. return WebInspector.PlatformFlavor.MacSnowLeopard;
  4337. case 7:
  4338. return WebInspector.PlatformFlavor.MacLion;
  4339. case 8:
  4340. return WebInspector.PlatformFlavor.MacMountainLion;
  4341. default:
  4342. return "";
  4343. }
  4344. }
  4345. }
  4346.  
  4347. if (!WebInspector._platformFlavor)
  4348. WebInspector._platformFlavor = detectFlavor();
  4349.  
  4350. return WebInspector._platformFlavor;
  4351. }
  4352.  
  4353. WebInspector.port = function()
  4354. {
  4355. if (!WebInspector._port)
  4356. WebInspector._port = InspectorFrontendHost.port();
  4357.  
  4358. return WebInspector._port;
  4359. }
  4360.  
  4361. WebInspector.installPortStyles = function()
  4362. {
  4363. var platform = WebInspector.platform();
  4364. document.body.addStyleClass("platform-" + platform);
  4365. var flavor = WebInspector.platformFlavor();
  4366. if (flavor)
  4367. document.body.addStyleClass("platform-" + flavor);
  4368. var port = WebInspector.port();
  4369. document.body.addStyleClass("port-" + port);
  4370. }
  4371.  
  4372. WebInspector._windowFocused = function(event)
  4373. {
  4374. if (event.target.document.nodeType === Node.DOCUMENT_NODE)
  4375. document.body.removeStyleClass("inactive");
  4376. }
  4377.  
  4378. WebInspector._windowBlurred = function(event)
  4379. {
  4380. if (event.target.document.nodeType === Node.DOCUMENT_NODE)
  4381. document.body.addStyleClass("inactive");
  4382. }
  4383.  
  4384. WebInspector.previousFocusElement = function()
  4385. {
  4386. return WebInspector._previousFocusElement;
  4387. }
  4388.  
  4389. WebInspector.currentFocusElement = function()
  4390. {
  4391. return WebInspector._currentFocusElement;
  4392. }
  4393.  
  4394. WebInspector._focusChanged = function(event)
  4395. {
  4396. WebInspector.setCurrentFocusElement(event.target);
  4397. }
  4398.  
  4399. WebInspector._textInputTypes = ["text", "search", "tel", "url", "email", "password"].keySet(); 
  4400. WebInspector._isTextEditingElement = function(element)
  4401. {
  4402. if (element instanceof HTMLInputElement)
  4403. return element.type in WebInspector._textInputTypes;
  4404.  
  4405. if (element instanceof HTMLTextAreaElement)
  4406. return true;
  4407.  
  4408. return false;
  4409. }
  4410.  
  4411. WebInspector.setCurrentFocusElement = function(x)
  4412. {
  4413. if (WebInspector._currentFocusElement !== x)
  4414. WebInspector._previousFocusElement = WebInspector._currentFocusElement;
  4415. WebInspector._currentFocusElement = x;
  4416.  
  4417. if (WebInspector._currentFocusElement) {
  4418. WebInspector._currentFocusElement.focus();
  4419.  
  4420.  
  4421.  
  4422.  
  4423. var selection = window.getSelection();
  4424. if (!WebInspector._isTextEditingElement(WebInspector._currentFocusElement) && selection.isCollapsed && !WebInspector._currentFocusElement.isInsertionCaretInside()) {
  4425. var selectionRange = WebInspector._currentFocusElement.ownerDocument.createRange();
  4426. selectionRange.setStart(WebInspector._currentFocusElement, 0);
  4427. selectionRange.setEnd(WebInspector._currentFocusElement, 0);
  4428.  
  4429. selection.removeAllRanges();
  4430. selection.addRange(selectionRange);
  4431. }
  4432. } else if (WebInspector._previousFocusElement)
  4433. WebInspector._previousFocusElement.blur();
  4434. }
  4435.  
  4436. WebInspector.restoreFocusFromElement = function(element)
  4437. {
  4438. if (element && element.isSelfOrAncestor(WebInspector.currentFocusElement()))
  4439. WebInspector.setCurrentFocusElement(WebInspector.previousFocusElement());
  4440. }
  4441.  
  4442. WebInspector.setToolbarColors = function(backgroundColor, color)
  4443. {
  4444. if (!WebInspector._themeStyleElement) {
  4445. WebInspector._themeStyleElement = document.createElement("style");
  4446. document.head.appendChild(WebInspector._themeStyleElement);
  4447. }
  4448. WebInspector._themeStyleElement.textContent =
  4449. "#toolbar {\
  4450.              background-image: none !important;\
  4451.              background-color: " + backgroundColor + " !important;\
  4452.          }\
  4453.          \
  4454.          .toolbar-label {\
  4455.              color: " + color + " !important;\
  4456.              text-shadow: none;\
  4457.          }";
  4458. }
  4459.  
  4460. WebInspector.resetToolbarColors = function()
  4461. {
  4462. if (WebInspector._themeStyleElement)
  4463. WebInspector._themeStyleElement.textContent = "";
  4464. }
  4465.  
  4466.  
  4467. WebInspector.highlightSearchResult = function(element, offset, length, domChanges)
  4468. {
  4469. var result = WebInspector.highlightSearchResults(element, [{offset: offset, length: length }], domChanges);
  4470. return result.length ? result[0] : null;
  4471. }
  4472.  
  4473.  
  4474. WebInspector.highlightSearchResults = function(element, resultRanges, changes)
  4475. {
  4476. return WebInspector.highlightRangesWithStyleClass(element, resultRanges, "webkit-search-result", changes);
  4477. }
  4478.  
  4479.  
  4480. WebInspector.highlightRangesWithStyleClass = function(element, resultRanges, styleClass, changes)
  4481. {
  4482. changes = changes || [];
  4483. var highlightNodes = [];
  4484. var lineText = element.textContent;
  4485. var ownerDocument = element.ownerDocument;
  4486. var textNodeSnapshot = ownerDocument.evaluate(".//text()", element, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  4487.  
  4488. var snapshotLength = textNodeSnapshot.snapshotLength;
  4489. if (snapshotLength === 0)
  4490. return highlightNodes;
  4491.  
  4492. var nodeRanges = [];
  4493. var rangeEndOffset = 0;
  4494. for (var i = 0; i < snapshotLength; ++i) {
  4495. var range = {};
  4496. range.offset = rangeEndOffset;
  4497. range.length = textNodeSnapshot.snapshotItem(i).textContent.length;
  4498. rangeEndOffset = range.offset + range.length;
  4499. nodeRanges.push(range);
  4500. }
  4501.  
  4502. var startIndex = 0;
  4503. for (var i = 0; i < resultRanges.length; ++i) {
  4504. var startOffset = resultRanges[i].offset;
  4505. var endOffset = startOffset + resultRanges[i].length;
  4506.  
  4507. while (startIndex < snapshotLength && nodeRanges[startIndex].offset + nodeRanges[startIndex].length <= startOffset)
  4508. startIndex++;
  4509. var endIndex = startIndex;
  4510. while (endIndex < snapshotLength && nodeRanges[endIndex].offset + nodeRanges[endIndex].length < endOffset)
  4511. endIndex++;
  4512. if (endIndex === snapshotLength)
  4513. break;
  4514.  
  4515. var highlightNode = ownerDocument.createElement("span");
  4516. highlightNode.className = styleClass;
  4517. highlightNode.textContent = lineText.substring(startOffset, endOffset);
  4518.  
  4519. var lastTextNode = textNodeSnapshot.snapshotItem(endIndex);
  4520. var lastText = lastTextNode.textContent;
  4521. lastTextNode.textContent = lastText.substring(endOffset - nodeRanges[endIndex].offset);
  4522. changes.push({ node: lastTextNode, type: "changed", oldText: lastText, newText: lastTextNode.textContent });
  4523.  
  4524. if (startIndex === endIndex) {
  4525. lastTextNode.parentElement.insertBefore(highlightNode, lastTextNode);
  4526. changes.push({ node: highlightNode, type: "added", nextSibling: lastTextNode, parent: lastTextNode.parentElement });
  4527. highlightNodes.push(highlightNode);
  4528.  
  4529. var prefixNode = ownerDocument.createTextNode(lastText.substring(0, startOffset - nodeRanges[startIndex].offset));
  4530. lastTextNode.parentElement.insertBefore(prefixNode, highlightNode);
  4531. changes.push({ node: prefixNode, type: "added", nextSibling: highlightNode, parent: lastTextNode.parentElement });
  4532. } else {
  4533. var firstTextNode = textNodeSnapshot.snapshotItem(startIndex);
  4534. var firstText = firstTextNode.textContent;
  4535. var anchorElement = firstTextNode.nextSibling;
  4536.  
  4537. firstTextNode.parentElement.insertBefore(highlightNode, anchorElement);
  4538. changes.push({ node: highlightNode, type: "added", nextSibling: anchorElement, parent: firstTextNode.parentElement });
  4539. highlightNodes.push(highlightNode);
  4540.  
  4541. firstTextNode.textContent = firstText.substring(0, startOffset - nodeRanges[startIndex].offset);
  4542. changes.push({ node: firstTextNode, type: "changed", oldText: firstText, newText: firstTextNode.textContent });
  4543.  
  4544. for (var j = startIndex + 1; j < endIndex; j++) {
  4545. var textNode = textNodeSnapshot.snapshotItem(j);
  4546. var text = textNode.textContent;
  4547. textNode.textContent = "";
  4548. changes.push({ node: textNode, type: "changed", oldText: text, newText: textNode.textContent });
  4549. }
  4550. }
  4551. startIndex = endIndex;
  4552. nodeRanges[startIndex].offset = endOffset;
  4553. nodeRanges[startIndex].length = lastTextNode.textContent.length;
  4554.  
  4555. }
  4556. return highlightNodes;
  4557. }
  4558.  
  4559. WebInspector.applyDomChanges = function(domChanges)
  4560. {
  4561. for (var i = 0, size = domChanges.length; i < size; ++i) {
  4562. var entry = domChanges[i];
  4563. switch (entry.type) {
  4564. case "added":
  4565. entry.parent.insertBefore(entry.node, entry.nextSibling);
  4566. break;
  4567. case "changed":
  4568. entry.node.textContent = entry.newText;
  4569. break;
  4570. }
  4571. }
  4572. }
  4573.  
  4574. WebInspector.revertDomChanges = function(domChanges)
  4575. {
  4576. for (var i = domChanges.length - 1; i >= 0; --i) {
  4577. var entry = domChanges[i];
  4578. switch (entry.type) {
  4579. case "added":
  4580. if (entry.node.parentElement)
  4581. entry.node.parentElement.removeChild(entry.node);
  4582. break;
  4583. case "changed":
  4584. entry.node.textContent = entry.oldText;
  4585. break;
  4586. }
  4587. }
  4588. }
  4589.  
  4590. WebInspector._coalescingLevel = 0;
  4591.  
  4592. WebInspector.startBatchUpdate = function()
  4593. {
  4594. if (!WebInspector._coalescingLevel)
  4595. WebInspector._postUpdateHandlers = new Map();
  4596. WebInspector._coalescingLevel++;
  4597. }
  4598.  
  4599. WebInspector.endBatchUpdate = function()
  4600. {
  4601. if (--WebInspector._coalescingLevel)
  4602. return;
  4603.  
  4604. var handlers = WebInspector._postUpdateHandlers;
  4605. delete WebInspector._postUpdateHandlers;
  4606.  
  4607. var keys = handlers.keys();
  4608. for (var i = 0; i < keys.length; ++i) {
  4609. var object = keys[i];
  4610. var methods = handlers.get(object).keys();
  4611. for (var j = 0; j < methods.length; ++j)
  4612. methods[j].call(object);
  4613. }
  4614. }
  4615.  
  4616.  
  4617. WebInspector.invokeOnceAfterBatchUpdate = function(object, method)
  4618. {
  4619. if (!WebInspector._coalescingLevel) {
  4620. method.call(object);
  4621. return;
  4622. }
  4623.  
  4624. var methods = WebInspector._postUpdateHandlers.get(object);
  4625. if (!methods) {
  4626. methods = new Map();
  4627. WebInspector._postUpdateHandlers.put(object, methods);
  4628. }
  4629. methods.put(method);
  4630. }
  4631.  
  4632. ;(function() {
  4633.  
  4634. function windowLoaded()
  4635. {
  4636. window.addEventListener("focus", WebInspector._windowFocused, false);
  4637. window.addEventListener("blur", WebInspector._windowBlurred, false);
  4638. document.addEventListener("focus", WebInspector._focusChanged.bind(this), true);
  4639. window.removeEventListener("DOMContentLoaded", windowLoaded, false);
  4640. }
  4641.  
  4642. window.addEventListener("DOMContentLoaded", windowLoaded, false);
  4643.  
  4644. })();
  4645.  
  4646.  
  4647.  
  4648.  
  4649.  
  4650.  
  4651. function InspectorBackendClass()
  4652. {
  4653. this._lastCallbackId = 1;
  4654. this._pendingResponsesCount = 0;
  4655. this._callbacks = {};
  4656. this._domainDispatchers = {};
  4657. this._eventArgs = {};
  4658. this._replyArgs = {};
  4659.  
  4660. this.dumpInspectorTimeStats = false;
  4661. this.dumpInspectorProtocolMessages = false;
  4662. this._initialized = false;
  4663. }
  4664.  
  4665. InspectorBackendClass.prototype = {
  4666. _wrap: function(callback, method)
  4667. {
  4668. var callbackId = this._lastCallbackId++;
  4669. if (!callback)
  4670. callback = function() {};
  4671.  
  4672. this._callbacks[callbackId] = callback;
  4673. callback.methodName = method;
  4674. if (this.dumpInspectorTimeStats)
  4675. callback.sendRequestTime = Date.now();
  4676.  
  4677. return callbackId;
  4678. },
  4679.  
  4680. registerCommand: function(method, signature, replyArgs)
  4681. {
  4682. var domainAndMethod = method.split(".");
  4683. var agentName = domainAndMethod[0] + "Agent";
  4684. if (!window[agentName])
  4685. window[agentName] = {};
  4686.  
  4687. window[agentName][domainAndMethod[1]] = this._sendMessageToBackend.bind(this, method, signature);
  4688. window[agentName][domainAndMethod[1]]["invoke"] = this._invoke.bind(this, method, signature);
  4689. this._replyArgs[method] = replyArgs;
  4690.  
  4691. this._initialized = true;
  4692. },
  4693.  
  4694. registerEvent: function(eventName, params)
  4695. {
  4696. this._eventArgs[eventName] = params;
  4697.  
  4698. this._initialized = true;
  4699. },
  4700.  
  4701. _invoke: function(method, signature, args, callback)
  4702. {
  4703. this._wrapCallbackAndSendMessageObject(method, args, callback);
  4704. },
  4705.  
  4706. _sendMessageToBackend: function(method, signature, vararg)
  4707. {
  4708. var args = Array.prototype.slice.call(arguments, 2);
  4709. var callback = (args.length && typeof args[args.length - 1] === "function") ? args.pop() : null;
  4710.  
  4711. var params = {};
  4712. var hasParams = false;
  4713. for (var i = 0; i < signature.length; ++i) {
  4714. var param = signature[i];
  4715. var paramName = param["name"];
  4716. var typeName = param["type"];
  4717. var optionalFlag = param["optional"];
  4718.  
  4719. if (!args.length && !optionalFlag) {
  4720. console.error("Protocol Error: Invalid number of arguments for method '" + method + "' call. It must have the following arguments '" + JSON.stringify(signature) + "'.");
  4721. return;
  4722. }
  4723.  
  4724. var value = args.shift();
  4725. if (optionalFlag && typeof value === "undefined") {
  4726. continue;
  4727. }
  4728.  
  4729. if (typeof value !== typeName) {
  4730. console.error("Protocol Error: Invalid type of argument '" + paramName + "' for method '" + method + "' call. It must be '" + typeName + "' but it is '" + typeof value + "'.");
  4731. return;
  4732. }
  4733.  
  4734. params[paramName] = value;
  4735. hasParams = true;
  4736. }
  4737.  
  4738. if (args.length === 1 && !callback) {
  4739. if (typeof args[0] !== "undefined") {
  4740. console.error("Protocol Error: Optional callback argument for method '" + method + "' call must be a function but its type is '" + typeof args[0] + "'.");
  4741. return;
  4742. }
  4743. }
  4744.  
  4745. this._wrapCallbackAndSendMessageObject(method, hasParams ? params : null, callback);
  4746. },
  4747.  
  4748. _wrapCallbackAndSendMessageObject: function(method, params, callback)
  4749. {
  4750. var messageObject = {};
  4751. messageObject.method = method;
  4752. if (params)
  4753. messageObject.params = params;
  4754. messageObject.id = this._wrap(callback, method);
  4755.  
  4756. if (this.dumpInspectorProtocolMessages)
  4757. console.log("frontend: " + JSON.stringify(messageObject));
  4758.  
  4759. ++this._pendingResponsesCount;
  4760. this.sendMessageObjectToBackend(messageObject);
  4761. },
  4762.  
  4763. sendMessageObjectToBackend: function(messageObject)
  4764. {
  4765. var message = JSON.stringify(messageObject);
  4766. InspectorFrontendHost.sendMessageToBackend(message);
  4767. },
  4768.  
  4769. registerDomainDispatcher: function(domain, dispatcher)
  4770. {
  4771. this._domainDispatchers[domain] = dispatcher;
  4772. },
  4773.  
  4774. dispatch: function(message)
  4775. {
  4776. if (this.dumpInspectorProtocolMessages)
  4777. console.log("backend: " + ((typeof message === "string") ? message : JSON.stringify(message)));
  4778.  
  4779. var messageObject = (typeof message === "string") ? JSON.parse(message) : message;
  4780.  
  4781. if ("id" in messageObject) { 
  4782. if (messageObject.error) {
  4783. if (messageObject.error.code !== -32000)
  4784. this.reportProtocolError(messageObject);
  4785. }
  4786.  
  4787. var callback = this._callbacks[messageObject.id];
  4788. if (callback) {
  4789. var argumentsArray = [];
  4790. if (messageObject.result) {
  4791. var paramNames = this._replyArgs[callback.methodName];
  4792. if (paramNames) {
  4793. for (var i = 0; i < paramNames.length; ++i)
  4794. argumentsArray.push(messageObject.result[paramNames[i]]);
  4795. }
  4796. }
  4797.  
  4798. var processingStartTime;
  4799. if (this.dumpInspectorTimeStats && callback.methodName)
  4800. processingStartTime = Date.now();
  4801.  
  4802. argumentsArray.unshift(messageObject.error ? messageObject.error.message : null);
  4803. callback.apply(null, argumentsArray);
  4804. --this._pendingResponsesCount;
  4805. delete this._callbacks[messageObject.id];
  4806.  
  4807. if (this.dumpInspectorTimeStats && callback.methodName)
  4808. console.log("time-stats: " + callback.methodName + " = " + (processingStartTime - callback.sendRequestTime) + " + " + (Date.now() - processingStartTime));
  4809. }
  4810.  
  4811. if (this._scripts && !this._pendingResponsesCount)
  4812. this.runAfterPendingDispatches();
  4813.  
  4814. return;
  4815. } else {
  4816. var method = messageObject.method.split(".");
  4817. var domainName = method[0];
  4818. var functionName = method[1];
  4819. if (!(domainName in this._domainDispatchers)) {
  4820. console.error("Protocol Error: the message is for non-existing domain '" + domainName + "'");
  4821. return;
  4822. }
  4823. var dispatcher = this._domainDispatchers[domainName];
  4824. if (!(functionName in dispatcher)) {
  4825. console.error("Protocol Error: Attempted to dispatch an unimplemented method '" + messageObject.method + "'");
  4826. return;
  4827. }
  4828.  
  4829. if (!this._eventArgs[messageObject.method]) {
  4830. console.error("Protocol Error: Attempted to dispatch an unspecified method '" + messageObject.method + "'");
  4831. return;
  4832. }
  4833.  
  4834. var params = [];
  4835. if (messageObject.params) {
  4836. var paramNames = this._eventArgs[messageObject.method];
  4837. for (var i = 0; i < paramNames.length; ++i)
  4838. params.push(messageObject.params[paramNames[i]]);
  4839. }
  4840.  
  4841. var processingStartTime;
  4842. if (this.dumpInspectorTimeStats)
  4843. processingStartTime = Date.now();
  4844.  
  4845. dispatcher[functionName].apply(dispatcher, params);
  4846.  
  4847. if (this.dumpInspectorTimeStats)
  4848. console.log("time-stats: " + messageObject.method + " = " + (Date.now() - processingStartTime));
  4849. }
  4850. },
  4851.  
  4852. reportProtocolError: function(messageObject)
  4853. {
  4854. console.error("Request with id = " + messageObject.id + " failed. " + messageObject.error);
  4855. },
  4856.  
  4857.  
  4858. runAfterPendingDispatches: function(script)
  4859. {
  4860. if (!this._scripts)
  4861. this._scripts = [];
  4862.  
  4863. if (script)
  4864. this._scripts.push(script);
  4865.  
  4866. if (!this._pendingResponsesCount) {
  4867. var scripts = this._scripts;
  4868. this._scripts = []
  4869. for (var id = 0; id < scripts.length; ++id)
  4870. scripts[id].call(this);
  4871. }
  4872. },
  4873.  
  4874. loadFromJSONIfNeeded: function(jsonUrl)
  4875. {
  4876. if (this._initialized)
  4877. return;
  4878.  
  4879. var xhr = new XMLHttpRequest();
  4880. xhr.open("GET", jsonUrl, false);
  4881. xhr.send(null);
  4882.  
  4883. var schema = JSON.parse(xhr.responseText);
  4884. var jsTypes = { integer: "number", array: "object" };
  4885. var rawTypes = {};
  4886.  
  4887. var domains = schema["domains"];
  4888. for (var i = 0; i < domains.length; ++i) {
  4889. var domain = domains[i];
  4890. for (var j = 0; domain.types && j < domain.types.length; ++j) {
  4891. var type = domain.types[j];
  4892. rawTypes[domain.domain + "." + type.id] = jsTypes[type.type] || type.type;
  4893. }
  4894. }
  4895.  
  4896. var result = [];
  4897. for (var i = 0; i < domains.length; ++i) {
  4898. var domain = domains[i];
  4899.  
  4900. var commands = domain["commands"] || [];    
  4901. for (var j = 0; j < commands.length; ++j) {
  4902. var command = commands[j];
  4903. var parameters = command["parameters"];
  4904. var paramsText = [];
  4905. for (var k = 0; parameters && k < parameters.length; ++k) {
  4906. var parameter = parameters[k];
  4907.  
  4908. var type;
  4909. if (parameter.type)
  4910. type = jsTypes[parameter.type] || parameter.type;
  4911. else {
  4912. var ref = parameter["$ref"];
  4913. if (ref.indexOf(".") !== -1)
  4914. type = rawTypes[ref];
  4915. else
  4916. type = rawTypes[domain.domain + "." + ref];
  4917. }
  4918.  
  4919. var text = "{\"name\": \"" + parameter.name + "\", \"type\": \"" + type + "\", \"optional\": " + (parameter.optional ? "true" : "false") + "}";
  4920. paramsText.push(text);
  4921. }
  4922.  
  4923. var returnsText = [];
  4924. var returns = command["returns"] || [];
  4925. for (var k = 0; k < returns.length; ++k) {
  4926. var parameter = returns[k];
  4927. returnsText.push("\"" + parameter.name + "\"");
  4928. }
  4929. result.push("InspectorBackend.registerCommand(\"" + domain.domain + "." + command.name + "\", [" + paramsText.join(", ") + "], [" + returnsText.join(", ") + "]);");
  4930. }
  4931.  
  4932. for (var j = 0; domain.events && j < domain.events.length; ++j) {
  4933. var event = domain.events[j];
  4934. var paramsText = [];
  4935. for (var k = 0; event.parameters && k < event.parameters.length; ++k) {
  4936. var parameter = event.parameters[k];
  4937. paramsText.push("\"" + parameter.name + "\"");
  4938. }
  4939. result.push("InspectorBackend.registerEvent(\"" + domain.domain + "." + event.name + "\", [" + paramsText.join(", ") + "]);");
  4940. }
  4941.  
  4942. result.push("InspectorBackend.register" + domain.domain + "Dispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, \"" + domain.domain + "\");");
  4943. }
  4944. eval(result.join("\n"));
  4945. }
  4946. }
  4947.  
  4948. InspectorBackend = new InspectorBackendClass();
  4949.  
  4950.  
  4951.  
  4952.  
  4953.  
  4954.  
  4955.  
  4956.  
  4957.  
  4958.  
  4959.  
  4960. InspectorBackend.registerInspectorDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "Inspector");
  4961. InspectorBackend.registerEvent("Inspector.evaluateForTestInFrontend", ["testCallId", "script"]);
  4962. InspectorBackend.registerEvent("Inspector.inspect", ["object", "hints"]);
  4963. InspectorBackend.registerEvent("Inspector.detached", ["reason"]);
  4964. InspectorBackend.registerCommand("Inspector.enable", [], []);
  4965. InspectorBackend.registerCommand("Inspector.disable", [], []);
  4966.  
  4967.  
  4968. InspectorBackend.registerMemoryDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "Memory");
  4969. InspectorBackend.registerCommand("Memory.getDOMNodeCount", [], ["domGroups", "strings"]);
  4970. InspectorBackend.registerCommand("Memory.getProcessMemoryDistribution", [{"name": "reportGraph", "type": "boolean", "optional": true}], ["distribution", "graph"]);
  4971.  
  4972.  
  4973. InspectorBackend.registerPageDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "Page");
  4974. InspectorBackend.registerEvent("Page.domContentEventFired", ["timestamp"]);
  4975. InspectorBackend.registerEvent("Page.loadEventFired", ["timestamp"]);
  4976. InspectorBackend.registerEvent("Page.frameNavigated", ["frame"]);
  4977. InspectorBackend.registerEvent("Page.frameDetached", ["frameId"]);
  4978. InspectorBackend.registerCommand("Page.enable", [], []);
  4979. InspectorBackend.registerCommand("Page.disable", [], []);
  4980. InspectorBackend.registerCommand("Page.addScriptToEvaluateOnLoad", [{"name": "scriptSource", "type": "string", "optional": false}], ["identifier"]);
  4981. InspectorBackend.registerCommand("Page.removeScriptToEvaluateOnLoad", [{"name": "identifier", "type": "string", "optional": false}], []);
  4982. InspectorBackend.registerCommand("Page.reload", [{"name": "ignoreCache", "type": "boolean", "optional": true}, {"name": "scriptToEvaluateOnLoad", "type": "string", "optional": true}, {"name": "scriptPreprocessor", "type": "string", "optional": true}], []);
  4983. InspectorBackend.registerCommand("Page.navigate", [{"name": "url", "type": "string", "optional": false}], []);
  4984. InspectorBackend.registerCommand("Page.getCookies", [], ["cookies", "cookiesString"]);
  4985. InspectorBackend.registerCommand("Page.deleteCookie", [{"name": "cookieName", "type": "string", "optional": false}, {"name": "domain", "type": "string", "optional": false}], []);
  4986. InspectorBackend.registerCommand("Page.getResourceTree", [], ["frameTree"]);
  4987. InspectorBackend.registerCommand("Page.getResourceContent", [{"name": "frameId", "type": "string", "optional": false}, {"name": "url", "type": "string", "optional": false}], ["content", "base64Encoded"]);
  4988. InspectorBackend.registerCommand("Page.searchInResource", [{"name": "frameId", "type": "string", "optional": false}, {"name": "url", "type": "string", "optional": false}, {"name": "query", "type": "string", "optional": false}, {"name": "caseSensitive", "type": "boolean", "optional": true}, {"name": "isRegex", "type": "boolean", "optional": true}], ["result"]);
  4989. InspectorBackend.registerCommand("Page.searchInResources", [{"name": "text", "type": "string", "optional": false}, {"name": "caseSensitive", "type": "boolean", "optional": true}, {"name": "isRegex", "type": "boolean", "optional": true}], ["result"]);
  4990. InspectorBackend.registerCommand("Page.setDocumentContent", [{"name": "frameId", "type": "string", "optional": false}, {"name": "html", "type": "string", "optional": false}], []);
  4991. InspectorBackend.registerCommand("Page.canOverrideDeviceMetrics", [], ["result"]);
  4992. InspectorBackend.registerCommand("Page.setDeviceMetricsOverride", [{"name": "width", "type": "number", "optional": false}, {"name": "height", "type": "number", "optional": false}, {"name": "fontScaleFactor", "type": "number", "optional": false}, {"name": "fitWindow", "type": "boolean", "optional": false}], []);
  4993. InspectorBackend.registerCommand("Page.setShowPaintRects", [{"name": "result", "type": "boolean", "optional": false}], []);
  4994. InspectorBackend.registerCommand("Page.canShowFPSCounter", [], ["show"]);
  4995. InspectorBackend.registerCommand("Page.setShowFPSCounter", [{"name": "show", "type": "boolean", "optional": false}], []);
  4996. InspectorBackend.registerCommand("Page.getScriptExecutionStatus", [], ["result"]);
  4997. InspectorBackend.registerCommand("Page.setScriptExecutionDisabled", [{"name": "value", "type": "boolean", "optional": false}], []);
  4998. InspectorBackend.registerCommand("Page.setGeolocationOverride", [{"name": "latitude", "type": "number", "optional": true}, {"name": "longitude", "type": "number", "optional": true}, {"name": "accuracy", "type": "number", "optional": true}], []);
  4999. InspectorBackend.registerCommand("Page.clearGeolocationOverride", [], []);
  5000. InspectorBackend.registerCommand("Page.canOverrideGeolocation", [], ["result"]);
  5001. InspectorBackend.registerCommand("Page.setDeviceOrientationOverride", [{"name": "alpha", "type": "number", "optional": false}, {"name": "beta", "type": "number", "optional": false}, {"name": "gamma", "type": "number", "optional": false}], []);
  5002. InspectorBackend.registerCommand("Page.clearDeviceOrientationOverride", [], []);
  5003. InspectorBackend.registerCommand("Page.canOverrideDeviceOrientation", [], ["result"]);
  5004. InspectorBackend.registerCommand("Page.setTouchEmulationEnabled", [{"name": "enabled", "type": "boolean", "optional": false}], []);
  5005. InspectorBackend.registerCommand("Page.setEmulatedMedia", [{"name": "media", "type": "string", "optional": false}], []);
  5006. InspectorBackend.registerCommand("Page.getCompositingBordersVisible", [], ["result"]);
  5007. InspectorBackend.registerCommand("Page.setCompositingBordersVisible", [{"name": "visible", "type": "boolean", "optional": false}], []);
  5008.  
  5009.  
  5010. InspectorBackend.registerRuntimeDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "Runtime");
  5011. InspectorBackend.registerEvent("Runtime.executionContextCreated", ["context"]);
  5012. InspectorBackend.registerCommand("Runtime.evaluate", [{"name": "expression", "type": "string", "optional": false}, {"name": "objectGroup", "type": "string", "optional": true}, {"name": "includeCommandLineAPI", "type": "boolean", "optional": true}, {"name": "doNotPauseOnExceptionsAndMuteConsole", "type": "boolean", "optional": true}, {"name": "contextId", "type": "number", "optional": true}, {"name": "returnByValue", "type": "boolean", "optional": true}, {"name": "generatePreview", "type": "boolean", "optional": true}], ["result", "wasThrown"]);
  5013. InspectorBackend.registerCommand("Runtime.callFunctionOn", [{"name": "objectId", "type": "string", "optional": false}, {"name": "functionDeclaration", "type": "string", "optional": false}, {"name": "arguments", "type": "object", "optional": true}, {"name": "doNotPauseOnExceptionsAndMuteConsole", "type": "boolean", "optional": true}, {"name": "returnByValue", "type": "boolean", "optional": true}, {"name": "generatePreview", "type": "boolean", "optional": true}], ["result", "wasThrown"]);
  5014. InspectorBackend.registerCommand("Runtime.getProperties", [{"name": "objectId", "type": "string", "optional": false}, {"name": "ownProperties", "type": "boolean", "optional": true}], ["result", "internalProperties"]);
  5015. InspectorBackend.registerCommand("Runtime.releaseObject", [{"name": "objectId", "type": "string", "optional": false}], []);
  5016. InspectorBackend.registerCommand("Runtime.releaseObjectGroup", [{"name": "objectGroup", "type": "string", "optional": false}], []);
  5017. InspectorBackend.registerCommand("Runtime.run", [], []);
  5018. InspectorBackend.registerCommand("Runtime.enable", [], []);
  5019. InspectorBackend.registerCommand("Runtime.disable", [], []);
  5020.  
  5021.  
  5022. InspectorBackend.registerConsoleDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "Console");
  5023. InspectorBackend.registerEvent("Console.messageAdded", ["message"]);
  5024. InspectorBackend.registerEvent("Console.messageRepeatCountUpdated", ["count"]);
  5025. InspectorBackend.registerEvent("Console.messagesCleared", []);
  5026. InspectorBackend.registerCommand("Console.enable", [], []);
  5027. InspectorBackend.registerCommand("Console.disable", [], []);
  5028. InspectorBackend.registerCommand("Console.clearMessages", [], []);
  5029. InspectorBackend.registerCommand("Console.setMonitoringXHREnabled", [{"name": "enabled", "type": "boolean", "optional": false}], []);
  5030. InspectorBackend.registerCommand("Console.addInspectedNode", [{"name": "nodeId", "type": "number", "optional": false}], []);
  5031. InspectorBackend.registerCommand("Console.addInspectedHeapObject", [{"name": "heapObjectId", "type": "number", "optional": false}], []);
  5032.  
  5033.  
  5034. InspectorBackend.registerNetworkDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "Network");
  5035. InspectorBackend.registerEvent("Network.requestWillBeSent", ["requestId", "frameId", "loaderId", "documentURL", "request", "timestamp", "initiator", "redirectResponse"]);
  5036. InspectorBackend.registerEvent("Network.requestServedFromCache", ["requestId"]);
  5037. InspectorBackend.registerEvent("Network.responseReceived", ["requestId", "frameId", "loaderId", "timestamp", "type", "response"]);
  5038. InspectorBackend.registerEvent("Network.dataReceived", ["requestId", "timestamp", "dataLength", "encodedDataLength"]);
  5039. InspectorBackend.registerEvent("Network.loadingFinished", ["requestId", "timestamp"]);
  5040. InspectorBackend.registerEvent("Network.loadingFailed", ["requestId", "timestamp", "errorText", "canceled"]);
  5041. InspectorBackend.registerEvent("Network.requestServedFromMemoryCache", ["requestId", "frameId", "loaderId", "documentURL", "timestamp", "initiator", "resource"]);
  5042. InspectorBackend.registerEvent("Network.webSocketWillSendHandshakeRequest", ["requestId", "timestamp", "request"]);
  5043. InspectorBackend.registerEvent("Network.webSocketHandshakeResponseReceived", ["requestId", "timestamp", "response"]);
  5044. InspectorBackend.registerEvent("Network.webSocketCreated", ["requestId", "url"]);
  5045. InspectorBackend.registerEvent("Network.webSocketClosed", ["requestId", "timestamp"]);
  5046. InspectorBackend.registerEvent("Network.webSocketFrameReceived", ["requestId", "timestamp", "response"]);
  5047. InspectorBackend.registerEvent("Network.webSocketFrameError", ["requestId", "timestamp", "errorMessage"]);
  5048. InspectorBackend.registerEvent("Network.webSocketFrameSent", ["requestId", "timestamp", "response"]);
  5049. InspectorBackend.registerCommand("Network.enable", [], []);
  5050. InspectorBackend.registerCommand("Network.disable", [], []);
  5051. InspectorBackend.registerCommand("Network.setUserAgentOverride", [{"name": "userAgent", "type": "string", "optional": false}], []);
  5052. InspectorBackend.registerCommand("Network.setExtraHTTPHeaders", [{"name": "headers", "type": "object", "optional": false}], []);
  5053. InspectorBackend.registerCommand("Network.getResponseBody", [{"name": "requestId", "type": "string", "optional": false}], ["body", "base64Encoded"]);
  5054. InspectorBackend.registerCommand("Network.replayXHR", [{"name": "requestId", "type": "string", "optional": false}], []);
  5055. InspectorBackend.registerCommand("Network.canClearBrowserCache", [], ["result"]);
  5056. InspectorBackend.registerCommand("Network.clearBrowserCache", [], []);
  5057. InspectorBackend.registerCommand("Network.canClearBrowserCookies", [], ["result"]);
  5058. InspectorBackend.registerCommand("Network.clearBrowserCookies", [], []);
  5059. InspectorBackend.registerCommand("Network.setCacheDisabled", [{"name": "cacheDisabled", "type": "boolean", "optional": false}], []);
  5060.  
  5061.  
  5062. InspectorBackend.registerDatabaseDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "Database");
  5063. InspectorBackend.registerEvent("Database.addDatabase", ["database"]);
  5064. InspectorBackend.registerCommand("Database.enable", [], []);
  5065. InspectorBackend.registerCommand("Database.disable", [], []);
  5066. InspectorBackend.registerCommand("Database.getDatabaseTableNames", [{"name": "databaseId", "type": "string", "optional": false}], ["tableNames"]);
  5067. InspectorBackend.registerCommand("Database.executeSQL", [{"name": "databaseId", "type": "string", "optional": false}, {"name": "query", "type": "string", "optional": false}], ["columnNames", "values", "sqlError"]);
  5068.  
  5069.  
  5070. InspectorBackend.registerIndexedDBDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "IndexedDB");
  5071. InspectorBackend.registerCommand("IndexedDB.enable", [], []);
  5072. InspectorBackend.registerCommand("IndexedDB.disable", [], []);
  5073. InspectorBackend.registerCommand("IndexedDB.requestDatabaseNamesForFrame", [{"name": "frameId", "type": "string", "optional": false}], ["securityOriginWithDatabaseNames"]);
  5074. InspectorBackend.registerCommand("IndexedDB.requestDatabase", [{"name": "frameId", "type": "string", "optional": false}, {"name": "databaseName", "type": "string", "optional": false}], ["databaseWithObjectStores"]);
  5075. InspectorBackend.registerCommand("IndexedDB.requestData", [{"name": "frameId", "type": "string", "optional": false}, {"name": "databaseName", "type": "string", "optional": false}, {"name": "objectStoreName", "type": "string", "optional": false}, {"name": "indexName", "type": "string", "optional": false}, {"name": "skipCount", "type": "number", "optional": false}, {"name": "pageSize", "type": "number", "optional": false}, {"name": "keyRange", "type": "object", "optional": true}], ["objectStoreDataEntries", "hasMore"]);
  5076.  
  5077.  
  5078. InspectorBackend.registerDOMStorageDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "DOMStorage");
  5079. InspectorBackend.registerEvent("DOMStorage.addDOMStorage", ["storage"]);
  5080. InspectorBackend.registerEvent("DOMStorage.domStorageUpdated", ["storageId"]);
  5081. InspectorBackend.registerCommand("DOMStorage.enable", [], []);
  5082. InspectorBackend.registerCommand("DOMStorage.disable", [], []);
  5083. InspectorBackend.registerCommand("DOMStorage.getDOMStorageEntries", [{"name": "storageId", "type": "string", "optional": false}], ["entries"]);
  5084. InspectorBackend.registerCommand("DOMStorage.setDOMStorageItem", [{"name": "storageId", "type": "string", "optional": false}, {"name": "key", "type": "string", "optional": false}, {"name": "value", "type": "string", "optional": false}], ["success"]);
  5085. InspectorBackend.registerCommand("DOMStorage.removeDOMStorageItem", [{"name": "storageId", "type": "string", "optional": false}, {"name": "key", "type": "string", "optional": false}], ["success"]);
  5086.  
  5087.  
  5088. InspectorBackend.registerApplicationCacheDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "ApplicationCache");
  5089. InspectorBackend.registerEvent("ApplicationCache.applicationCacheStatusUpdated", ["frameId", "manifestURL", "status"]);
  5090. InspectorBackend.registerEvent("ApplicationCache.networkStateUpdated", ["isNowOnline"]);
  5091. InspectorBackend.registerCommand("ApplicationCache.getFramesWithManifests", [], ["frameIds"]);
  5092. InspectorBackend.registerCommand("ApplicationCache.enable", [], []);
  5093. InspectorBackend.registerCommand("ApplicationCache.getManifestForFrame", [{"name": "frameId", "type": "string", "optional": false}], ["manifestURL"]);
  5094. InspectorBackend.registerCommand("ApplicationCache.getApplicationCacheForFrame", [{"name": "frameId", "type": "string", "optional": false}], ["applicationCache"]);
  5095.  
  5096.  
  5097. InspectorBackend.registerFileSystemDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "FileSystem");
  5098. InspectorBackend.registerCommand("FileSystem.enable", [], []);
  5099. InspectorBackend.registerCommand("FileSystem.disable", [], []);
  5100. InspectorBackend.registerCommand("FileSystem.requestFileSystemRoot", [{"name": "origin", "type": "string", "optional": false}, {"name": "type", "type": "string", "optional": false}], ["errorCode", "root"]);
  5101. InspectorBackend.registerCommand("FileSystem.requestDirectoryContent", [{"name": "url", "type": "string", "optional": false}], ["errorCode", "entries"]);
  5102. InspectorBackend.registerCommand("FileSystem.requestMetadata", [{"name": "url", "type": "string", "optional": false}], ["errorCode", "metadata"]);
  5103. InspectorBackend.registerCommand("FileSystem.requestFileContent", [{"name": "url", "type": "string", "optional": false}, {"name": "readAsText", "type": "boolean", "optional": false}, {"name": "start", "type": "number", "optional": true}, {"name": "end", "type": "number", "optional": true}, {"name": "charset", "type": "string", "optional": true}], ["errorCode", "content", "charset"]);
  5104. InspectorBackend.registerCommand("FileSystem.deleteEntry", [{"name": "url", "type": "string", "optional": false}], ["errorCode"]);
  5105.  
  5106.  
  5107. InspectorBackend.registerDOMDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "DOM");
  5108. InspectorBackend.registerEvent("DOM.documentUpdated", []);
  5109. InspectorBackend.registerEvent("DOM.setChildNodes", ["parentId", "nodes"]);
  5110. InspectorBackend.registerEvent("DOM.attributeModified", ["nodeId", "name", "value"]);
  5111. InspectorBackend.registerEvent("DOM.attributeRemoved", ["nodeId", "name"]);
  5112. InspectorBackend.registerEvent("DOM.inlineStyleInvalidated", ["nodeIds"]);
  5113. InspectorBackend.registerEvent("DOM.characterDataModified", ["nodeId", "characterData"]);
  5114. InspectorBackend.registerEvent("DOM.childNodeCountUpdated", ["nodeId", "childNodeCount"]);
  5115. InspectorBackend.registerEvent("DOM.childNodeInserted", ["parentNodeId", "previousNodeId", "node"]);
  5116. InspectorBackend.registerEvent("DOM.childNodeRemoved", ["parentNodeId", "nodeId"]);
  5117. InspectorBackend.registerEvent("DOM.shadowRootPushed", ["hostId", "root"]);
  5118. InspectorBackend.registerEvent("DOM.shadowRootPopped", ["hostId", "rootId"]);
  5119. InspectorBackend.registerCommand("DOM.getDocument", [], ["root"]);
  5120. InspectorBackend.registerCommand("DOM.requestChildNodes", [{"name": "nodeId", "type": "number", "optional": false}], []);
  5121. InspectorBackend.registerCommand("DOM.querySelector", [{"name": "nodeId", "type": "number", "optional": false}, {"name": "selector", "type": "string", "optional": false}], ["nodeId"]);
  5122. InspectorBackend.registerCommand("DOM.querySelectorAll", [{"name": "nodeId", "type": "number", "optional": false}, {"name": "selector", "type": "string", "optional": false}], ["nodeIds"]);
  5123. InspectorBackend.registerCommand("DOM.setNodeName", [{"name": "nodeId", "type": "number", "optional": false}, {"name": "name", "type": "string", "optional": false}], ["nodeId"]);
  5124. InspectorBackend.registerCommand("DOM.setNodeValue", [{"name": "nodeId", "type": "number", "optional": false}, {"name": "value", "type": "string", "optional": false}], []);
  5125. InspectorBackend.registerCommand("DOM.removeNode", [{"name": "nodeId", "type": "number", "optional": false}], []);
  5126. InspectorBackend.registerCommand("DOM.setAttributeValue", [{"name": "nodeId", "type": "number", "optional": false}, {"name": "name", "type": "string", "optional": false}, {"name": "value", "type": "string", "optional": false}], []);
  5127. InspectorBackend.registerCommand("DOM.setAttributesAsText", [{"name": "nodeId", "type": "number", "optional": false}, {"name": "text", "type": "string", "optional": false}, {"name": "name", "type": "string", "optional": true}], []);
  5128. InspectorBackend.registerCommand("DOM.removeAttribute", [{"name": "nodeId", "type": "number", "optional": false}, {"name": "name", "type": "string", "optional": false}], []);
  5129. InspectorBackend.registerCommand("DOM.getEventListenersForNode", [{"name": "nodeId", "type": "number", "optional": false}], ["listeners"]);
  5130. InspectorBackend.registerCommand("DOM.getOuterHTML", [{"name": "nodeId", "type": "number", "optional": false}], ["outerHTML"]);
  5131. InspectorBackend.registerCommand("DOM.setOuterHTML", [{"name": "nodeId", "type": "number", "optional": false}, {"name": "outerHTML", "type": "string", "optional": false}], []);
  5132. InspectorBackend.registerCommand("DOM.performSearch", [{"name": "query", "type": "string", "optional": false}], ["searchId", "resultCount"]);
  5133. InspectorBackend.registerCommand("DOM.getSearchResults", [{"name": "searchId", "type": "string", "optional": false}, {"name": "fromIndex", "type": "number", "optional": false}, {"name": "toIndex", "type": "number", "optional": false}], ["nodeIds"]);
  5134. InspectorBackend.registerCommand("DOM.discardSearchResults", [{"name": "searchId", "type": "string", "optional": false}], []);
  5135. InspectorBackend.registerCommand("DOM.requestNode", [{"name": "objectId", "type": "string", "optional": false}], ["nodeId"]);
  5136. InspectorBackend.registerCommand("DOM.setInspectModeEnabled", [{"name": "enabled", "type": "boolean", "optional": false}, {"name": "highlightConfig", "type": "object", "optional": true}], []);
  5137. InspectorBackend.registerCommand("DOM.highlightRect", [{"name": "x", "type": "number", "optional": false}, {"name": "y", "type": "number", "optional": false}, {"name": "width", "type": "number", "optional": false}, {"name": "height", "type": "number", "optional": false}, {"name": "color", "type": "object", "optional": true}, {"name": "outlineColor", "type": "object", "optional": true}], []);
  5138. InspectorBackend.registerCommand("DOM.highlightNode", [{"name": "highlightConfig", "type": "object", "optional": false}, {"name": "nodeId", "type": "number", "optional": true}, {"name": "objectId", "type": "string", "optional": true}], []);
  5139. InspectorBackend.registerCommand("DOM.hideHighlight", [], []);
  5140. InspectorBackend.registerCommand("DOM.highlightFrame", [{"name": "frameId", "type": "string", "optional": false}, {"name": "contentColor", "type": "object", "optional": true}, {"name": "contentOutlineColor", "type": "object", "optional": true}], []);
  5141. InspectorBackend.registerCommand("DOM.pushNodeByPathToFrontend", [{"name": "path", "type": "string", "optional": false}], ["nodeId"]);
  5142. InspectorBackend.registerCommand("DOM.resolveNode", [{"name": "nodeId", "type": "number", "optional": false}, {"name": "objectGroup", "type": "string", "optional": true}], ["object"]);
  5143. InspectorBackend.registerCommand("DOM.getAttributes", [{"name": "nodeId", "type": "number", "optional": false}], ["attributes"]);
  5144. InspectorBackend.registerCommand("DOM.moveTo", [{"name": "nodeId", "type": "number", "optional": false}, {"name": "targetNodeId", "type": "number", "optional": false}, {"name": "insertBeforeNodeId", "type": "number", "optional": true}], ["nodeId"]);
  5145. InspectorBackend.registerCommand("DOM.undo", [], []);
  5146. InspectorBackend.registerCommand("DOM.redo", [], []);
  5147. InspectorBackend.registerCommand("DOM.markUndoableState", [], []);
  5148. InspectorBackend.registerCommand("DOM.focus", [{"name": "nodeId", "type": "number", "optional": false}], []);
  5149.  
  5150.  
  5151. InspectorBackend.registerCSSDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "CSS");
  5152. InspectorBackend.registerEvent("CSS.mediaQueryResultChanged", []);
  5153. InspectorBackend.registerEvent("CSS.styleSheetChanged", ["styleSheetId"]);
  5154. InspectorBackend.registerEvent("CSS.namedFlowCreated", ["namedFlow"]);
  5155. InspectorBackend.registerEvent("CSS.namedFlowRemoved", ["documentNodeId", "flowName"]);
  5156. InspectorBackend.registerEvent("CSS.regionLayoutUpdated", ["namedFlow"]);
  5157. InspectorBackend.registerCommand("CSS.enable", [], []);
  5158. InspectorBackend.registerCommand("CSS.disable", [], []);
  5159. InspectorBackend.registerCommand("CSS.getMatchedStylesForNode", [{"name": "nodeId", "type": "number", "optional": false}, {"name": "includePseudo", "type": "boolean", "optional": true}, {"name": "includeInherited", "type": "boolean", "optional": true}], ["matchedCSSRules", "pseudoElements", "inherited"]);
  5160. InspectorBackend.registerCommand("CSS.getInlineStylesForNode", [{"name": "nodeId", "type": "number", "optional": false}], ["inlineStyle", "attributesStyle"]);
  5161. InspectorBackend.registerCommand("CSS.getComputedStyleForNode", [{"name": "nodeId", "type": "number", "optional": false}], ["computedStyle"]);
  5162. InspectorBackend.registerCommand("CSS.getAllStyleSheets", [], ["headers"]);
  5163. InspectorBackend.registerCommand("CSS.getStyleSheet", [{"name": "styleSheetId", "type": "string", "optional": false}], ["styleSheet"]);
  5164. InspectorBackend.registerCommand("CSS.getStyleSheetText", [{"name": "styleSheetId", "type": "string", "optional": false}], ["text"]);
  5165. InspectorBackend.registerCommand("CSS.setStyleSheetText", [{"name": "styleSheetId", "type": "string", "optional": false}, {"name": "text", "type": "string", "optional": false}], []);
  5166. InspectorBackend.registerCommand("CSS.setPropertyText", [{"name": "styleId", "type": "object", "optional": false}, {"name": "propertyIndex", "type": "number", "optional": false}, {"name": "text", "type": "string", "optional": false}, {"name": "overwrite", "type": "boolean", "optional": false}], ["style"]);
  5167. InspectorBackend.registerCommand("CSS.toggleProperty", [{"name": "styleId", "type": "object", "optional": false}, {"name": "propertyIndex", "type": "number", "optional": false}, {"name": "disable", "type": "boolean", "optional": false}], ["style"]);
  5168. InspectorBackend.registerCommand("CSS.setRuleSelector", [{"name": "ruleId", "type": "object", "optional": false}, {"name": "selector", "type": "string", "optional": false}], ["rule"]);
  5169. InspectorBackend.registerCommand("CSS.addRule", [{"name": "contextNodeId", "type": "number", "optional": false}, {"name": "selector", "type": "string", "optional": false}], ["rule"]);
  5170. InspectorBackend.registerCommand("CSS.getSupportedCSSProperties", [], ["cssProperties"]);
  5171. InspectorBackend.registerCommand("CSS.forcePseudoState", [{"name": "nodeId", "type": "number", "optional": false}, {"name": "forcedPseudoClasses", "type": "object", "optional": false}], []);
  5172. InspectorBackend.registerCommand("CSS.startSelectorProfiler", [], []);
  5173. InspectorBackend.registerCommand("CSS.stopSelectorProfiler", [], ["profile"]);
  5174. InspectorBackend.registerCommand("CSS.getNamedFlowCollection", [{"name": "documentNodeId", "type": "number", "optional": false}], ["namedFlows"]);
  5175.  
  5176.  
  5177. InspectorBackend.registerTimelineDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "Timeline");
  5178. InspectorBackend.registerEvent("Timeline.eventRecorded", ["record"]);
  5179. InspectorBackend.registerCommand("Timeline.start", [{"name": "maxCallStackDepth", "type": "number", "optional": true}], []);
  5180. InspectorBackend.registerCommand("Timeline.stop", [], []);
  5181. InspectorBackend.registerCommand("Timeline.setIncludeMemoryDetails", [{"name": "enabled", "type": "boolean", "optional": false}], []);
  5182. InspectorBackend.registerCommand("Timeline.supportsFrameInstrumentation", [], ["result"]);
  5183. InspectorBackend.registerCommand("Timeline.canMonitorMainThread", [], ["result"]);
  5184.  
  5185.  
  5186. InspectorBackend.registerDebuggerDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "Debugger");
  5187. InspectorBackend.registerEvent("Debugger.globalObjectCleared", []);
  5188. InspectorBackend.registerEvent("Debugger.scriptParsed", ["scriptId", "url", "startLine", "startColumn", "endLine", "endColumn", "isContentScript", "sourceMapURL", "hasSourceURL"]);
  5189. InspectorBackend.registerEvent("Debugger.scriptFailedToParse", ["url", "scriptSource", "startLine", "errorLine", "errorMessage"]);
  5190. InspectorBackend.registerEvent("Debugger.breakpointResolved", ["breakpointId", "location"]);
  5191. InspectorBackend.registerEvent("Debugger.paused", ["callFrames", "reason", "data"]);
  5192. InspectorBackend.registerEvent("Debugger.resumed", []);
  5193. InspectorBackend.registerCommand("Debugger.causesRecompilation", [], ["result"]);
  5194. InspectorBackend.registerCommand("Debugger.supportsSeparateScriptCompilationAndExecution", [], ["result"]);
  5195. InspectorBackend.registerCommand("Debugger.enable", [], []);
  5196. InspectorBackend.registerCommand("Debugger.disable", [], []);
  5197. InspectorBackend.registerCommand("Debugger.setBreakpointsActive", [{"name": "active", "type": "boolean", "optional": false}], []);
  5198. InspectorBackend.registerCommand("Debugger.setBreakpointByUrl", [{"name": "lineNumber", "type": "number", "optional": false}, {"name": "url", "type": "string", "optional": true}, {"name": "urlRegex", "type": "string", "optional": true}, {"name": "columnNumber", "type": "number", "optional": true}, {"name": "condition", "type": "string", "optional": true}], ["breakpointId", "locations"]);
  5199. InspectorBackend.registerCommand("Debugger.setBreakpoint", [{"name": "location", "type": "object", "optional": false}, {"name": "condition", "type": "string", "optional": true}], ["breakpointId", "actualLocation"]);
  5200. InspectorBackend.registerCommand("Debugger.removeBreakpoint", [{"name": "breakpointId", "type": "string", "optional": false}], []);
  5201. InspectorBackend.registerCommand("Debugger.continueToLocation", [{"name": "location", "type": "object", "optional": false}], []);
  5202. InspectorBackend.registerCommand("Debugger.stepOver", [], []);
  5203. InspectorBackend.registerCommand("Debugger.stepInto", [], []);
  5204. InspectorBackend.registerCommand("Debugger.stepOut", [], []);
  5205. InspectorBackend.registerCommand("Debugger.pause", [], []);
  5206. InspectorBackend.registerCommand("Debugger.resume", [], []);
  5207. InspectorBackend.registerCommand("Debugger.searchInContent", [{"name": "scriptId", "type": "string", "optional": false}, {"name": "query", "type": "string", "optional": false}, {"name": "caseSensitive", "type": "boolean", "optional": true}, {"name": "isRegex", "type": "boolean", "optional": true}], ["result"]);
  5208. InspectorBackend.registerCommand("Debugger.canSetScriptSource", [], ["result"]);
  5209. InspectorBackend.registerCommand("Debugger.setScriptSource", [{"name": "scriptId", "type": "string", "optional": false}, {"name": "scriptSource", "type": "string", "optional": false}, {"name": "preview", "type": "boolean", "optional": true}], ["callFrames", "result"]);
  5210. InspectorBackend.registerCommand("Debugger.restartFrame", [{"name": "callFrameId", "type": "string", "optional": false}], ["callFrames", "result"]);
  5211. InspectorBackend.registerCommand("Debugger.getScriptSource", [{"name": "scriptId", "type": "string", "optional": false}], ["scriptSource"]);
  5212. InspectorBackend.registerCommand("Debugger.getFunctionDetails", [{"name": "functionId", "type": "string", "optional": false}], ["details"]);
  5213. InspectorBackend.registerCommand("Debugger.setPauseOnExceptions", [{"name": "state", "type": "string", "optional": false}], []);
  5214. InspectorBackend.registerCommand("Debugger.evaluateOnCallFrame", [{"name": "callFrameId", "type": "string", "optional": false}, {"name": "expression", "type": "string", "optional": false}, {"name": "objectGroup", "type": "string", "optional": true}, {"name": "includeCommandLineAPI", "type": "boolean", "optional": true}, {"name": "doNotPauseOnExceptionsAndMuteConsole", "type": "boolean", "optional": true}, {"name": "returnByValue", "type": "boolean", "optional": true}, {"name": "generatePreview", "type": "boolean", "optional": true}], ["result", "wasThrown"]);
  5215. InspectorBackend.registerCommand("Debugger.compileScript", [{"name": "expression", "type": "string", "optional": false}, {"name": "sourceURL", "type": "string", "optional": false}], ["scriptId", "syntaxErrorMessage"]);
  5216. InspectorBackend.registerCommand("Debugger.runScript", [{"name": "scriptId", "type": "string", "optional": false}, {"name": "contextId", "type": "number", "optional": true}, {"name": "objectGroup", "type": "string", "optional": true}, {"name": "doNotPauseOnExceptionsAndMuteConsole", "type": "boolean", "optional": true}], ["result", "wasThrown"]);
  5217. InspectorBackend.registerCommand("Debugger.setOverlayMessage", [{"name": "message", "type": "string", "optional": true}], []);
  5218.  
  5219.  
  5220. InspectorBackend.registerCommand("DOMDebugger.setDOMBreakpoint", [{"name": "nodeId", "type": "number", "optional": false}, {"name": "type", "type": "string", "optional": false}], []);
  5221. InspectorBackend.registerCommand("DOMDebugger.removeDOMBreakpoint", [{"name": "nodeId", "type": "number", "optional": false}, {"name": "type", "type": "string", "optional": false}], []);
  5222. InspectorBackend.registerCommand("DOMDebugger.setEventListenerBreakpoint", [{"name": "eventName", "type": "string", "optional": false}], []);
  5223. InspectorBackend.registerCommand("DOMDebugger.removeEventListenerBreakpoint", [{"name": "eventName", "type": "string", "optional": false}], []);
  5224. InspectorBackend.registerCommand("DOMDebugger.setInstrumentationBreakpoint", [{"name": "eventName", "type": "string", "optional": false}], []);
  5225. InspectorBackend.registerCommand("DOMDebugger.removeInstrumentationBreakpoint", [{"name": "eventName", "type": "string", "optional": false}], []);
  5226. InspectorBackend.registerCommand("DOMDebugger.setXHRBreakpoint", [{"name": "url", "type": "string", "optional": false}], []);
  5227. InspectorBackend.registerCommand("DOMDebugger.removeXHRBreakpoint", [{"name": "url", "type": "string", "optional": false}], []);
  5228.  
  5229.  
  5230. InspectorBackend.registerProfilerDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "Profiler");
  5231. InspectorBackend.registerEvent("Profiler.addProfileHeader", ["header"]);
  5232. InspectorBackend.registerEvent("Profiler.addHeapSnapshotChunk", ["uid", "chunk"]);
  5233. InspectorBackend.registerEvent("Profiler.finishHeapSnapshot", ["uid"]);
  5234. InspectorBackend.registerEvent("Profiler.setRecordingProfile", ["isProfiling"]);
  5235. InspectorBackend.registerEvent("Profiler.resetProfiles", []);
  5236. InspectorBackend.registerEvent("Profiler.reportHeapSnapshotProgress", ["done", "total"]);
  5237. InspectorBackend.registerCommand("Profiler.causesRecompilation", [], ["result"]);
  5238. InspectorBackend.registerCommand("Profiler.isSampling", [], ["result"]);
  5239. InspectorBackend.registerCommand("Profiler.hasHeapProfiler", [], ["result"]);
  5240. InspectorBackend.registerCommand("Profiler.enable", [], []);
  5241. InspectorBackend.registerCommand("Profiler.disable", [], []);
  5242. InspectorBackend.registerCommand("Profiler.start", [], []);
  5243. InspectorBackend.registerCommand("Profiler.stop", [], []);
  5244. InspectorBackend.registerCommand("Profiler.getProfileHeaders", [], ["headers"]);
  5245. InspectorBackend.registerCommand("Profiler.getProfile", [{"name": "type", "type": "string", "optional": false}, {"name": "uid", "type": "number", "optional": false}], ["profile"]);
  5246. InspectorBackend.registerCommand("Profiler.removeProfile", [{"name": "type", "type": "string", "optional": false}, {"name": "uid", "type": "number", "optional": false}], []);
  5247. InspectorBackend.registerCommand("Profiler.clearProfiles", [], []);
  5248. InspectorBackend.registerCommand("Profiler.takeHeapSnapshot", [], []);
  5249. InspectorBackend.registerCommand("Profiler.collectGarbage", [], []);
  5250. InspectorBackend.registerCommand("Profiler.getObjectByHeapObjectId", [{"name": "objectId", "type": "string", "optional": false}, {"name": "objectGroup", "type": "string", "optional": true}], ["result"]);
  5251. InspectorBackend.registerCommand("Profiler.getHeapObjectId", [{"name": "objectId", "type": "string", "optional": false}], ["heapSnapshotObjectId"]);
  5252.  
  5253.  
  5254. InspectorBackend.registerWorkerDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "Worker");
  5255. InspectorBackend.registerEvent("Worker.workerCreated", ["workerId", "url", "inspectorConnected"]);
  5256. InspectorBackend.registerEvent("Worker.workerTerminated", ["workerId"]);
  5257. InspectorBackend.registerEvent("Worker.dispatchMessageFromWorker", ["workerId", "message"]);
  5258. InspectorBackend.registerEvent("Worker.disconnectedFromWorker", []);
  5259. InspectorBackend.registerCommand("Worker.enable", [], []);
  5260. InspectorBackend.registerCommand("Worker.disable", [], []);
  5261. InspectorBackend.registerCommand("Worker.sendMessageToWorker", [{"name": "workerId", "type": "number", "optional": false}, {"name": "message", "type": "object", "optional": false}], []);
  5262. InspectorBackend.registerCommand("Worker.connectToWorker", [{"name": "workerId", "type": "number", "optional": false}], []);
  5263. InspectorBackend.registerCommand("Worker.disconnectFromWorker", [{"name": "workerId", "type": "number", "optional": false}], []);
  5264. InspectorBackend.registerCommand("Worker.setAutoconnectToWorkers", [{"name": "value", "type": "boolean", "optional": false}], []);
  5265.  
  5266.  
  5267. InspectorBackend.registerCanvasDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "Canvas");
  5268. InspectorBackend.registerCommand("Canvas.enable", [], []);
  5269. InspectorBackend.registerCommand("Canvas.disable", [], []);
  5270. InspectorBackend.registerCommand("Canvas.dropTraceLog", [{"name": "traceLogId", "type": "string", "optional": false}], []);
  5271. InspectorBackend.registerCommand("Canvas.captureFrame", [], ["traceLogId"]);
  5272. InspectorBackend.registerCommand("Canvas.startCapturing", [], ["traceLogId"]);
  5273. InspectorBackend.registerCommand("Canvas.stopCapturing", [{"name": "traceLogId", "type": "string", "optional": false}], []);
  5274. InspectorBackend.registerCommand("Canvas.getTraceLog", [{"name": "traceLogId", "type": "string", "optional": false}, {"name": "startOffset", "type": "number", "optional": true}], ["traceLog"]);
  5275. InspectorBackend.registerCommand("Canvas.replayTraceLog", [{"name": "traceLogId", "type": "string", "optional": false}, {"name": "stepNo", "type": "number", "optional": false}], ["screenshotDataUrl"]);
  5276.  
  5277.  
  5278. InspectorBackend.registerInputDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "Input");
  5279. InspectorBackend.registerCommand("Input.dispatchKeyEvent", [{"name": "type", "type": "string", "optional": false}, {"name": "modifiers", "type": "number", "optional": true}, {"name": "timestamp", "type": "number", "optional": true}, {"name": "text", "type": "string", "optional": true}, {"name": "unmodifiedText", "type": "string", "optional": true}, {"name": "keyIdentifier", "type": "string", "optional": true}, {"name": "windowsVirtualKeyCode", "type": "number", "optional": true}, {"name": "nativeVirtualKeyCode", "type": "number", "optional": true}, {"name": "macCharCode", "type": "number", "optional": true}, {"name": "autoRepeat", "type": "boolean", "optional": true}, {"name": "isKeypad", "type": "boolean", "optional": true}, {"name": "isSystemKey", "type": "boolean", "optional": true}], []);
  5280. InspectorBackend.registerCommand("Input.dispatchMouseEvent", [{"name": "type", "type": "string", "optional": false}, {"name": "x", "type": "number", "optional": false}, {"name": "y", "type": "number", "optional": false}, {"name": "modifiers", "type": "number", "optional": true}, {"name": "timestamp", "type": "number", "optional": true}, {"name": "button", "type": "string", "optional": true}, {"name": "clickCount", "type": "number", "optional": true}], []);
  5281.  
  5282.  
  5283. InspectorBackend.registerLayerTreeDispatcher = InspectorBackend.registerDomainDispatcher.bind(InspectorBackend, "LayerTree");
  5284. InspectorBackend.registerEvent("LayerTree.layerTreeDidChange", []);
  5285. InspectorBackend.registerCommand("LayerTree.enable", [], []);
  5286. InspectorBackend.registerCommand("LayerTree.disable", [], []);
  5287. InspectorBackend.registerCommand("LayerTree.getLayerTree", [], ["layerTree"]);
  5288. InspectorBackend.registerCommand("LayerTree.nodeIdForLayerId", [{"name": "layerId", "type": "string", "optional": false}], ["nodeId"]);
  5289.  
  5290.  
  5291.  
  5292.  
  5293.  
  5294.  
  5295.  
  5296. if (!window.InspectorExtensionRegistry) {
  5297.  
  5298.  
  5299. WebInspector.InspectorExtensionRegistryStub = function()
  5300. {
  5301. }
  5302.  
  5303. WebInspector.InspectorExtensionRegistryStub.prototype = {
  5304. getExtensionsAsync: function()
  5305. {
  5306. }
  5307. }
  5308.  
  5309. var InspectorExtensionRegistry = new WebInspector.InspectorExtensionRegistryStub();
  5310.  
  5311. }
  5312.  
  5313.  
  5314.  
  5315.  
  5316.  
  5317. var InspectorFrontendAPI = {
  5318. _pendingCommands: [],
  5319.  
  5320. isDebuggingEnabled: function()
  5321. {
  5322. return WebInspector.debuggerModel.debuggerEnabled();
  5323. },
  5324.  
  5325. setDebuggingEnabled: function(enabled)
  5326. {
  5327. if (enabled) {
  5328. WebInspector.debuggerModel.enableDebugger();
  5329. WebInspector.showPanel("scripts");
  5330. } else
  5331. WebInspector.debuggerModel.disableDebugger();
  5332. },
  5333.  
  5334. isTimelineProfilingEnabled: function()
  5335. {
  5336. return WebInspector.panels.timeline && WebInspector.panels.timeline.timelineProfilingEnabled;
  5337. },
  5338.  
  5339. setTimelineProfilingEnabled: function(enabled)
  5340. {
  5341. WebInspector.showPanel("timeline").setTimelineProfilingEnabled(enabled);
  5342. },
  5343.  
  5344. isProfilingJavaScript: function()
  5345. {
  5346. return WebInspector.panels.profiles && WebInspector.CPUProfileType.instance && WebInspector.CPUProfileType.instance.isRecordingProfile();
  5347. },
  5348.  
  5349. startProfilingJavaScript: function()
  5350. {
  5351. WebInspector.showPanel("profiles").enableProfiler();
  5352. if (WebInspector.CPUProfileType.instance)
  5353. WebInspector.CPUProfileType.instance.startRecordingProfile();
  5354. },
  5355.  
  5356. stopProfilingJavaScript: function()
  5357. {
  5358. WebInspector.showPanel("profiles");
  5359. if (WebInspector.CPUProfileType.instance)
  5360. WebInspector.CPUProfileType.instance.stopRecordingProfile();
  5361. },
  5362.  
  5363. setAttachedWindow: function(side)
  5364. {
  5365.  
  5366. },
  5367.  
  5368. setDockSide: function(side)
  5369. {
  5370. if (WebInspector.dockController)
  5371. WebInspector.dockController.setDockSide(side);
  5372. },
  5373.  
  5374. showConsole: function()
  5375. {
  5376. WebInspector.showPanel("console");
  5377. },
  5378.  
  5379. showMainResourceForFrame: function(frameId)
  5380. {
  5381.  
  5382. },
  5383.  
  5384. showResources: function()
  5385. {
  5386. WebInspector.showPanel("resources");
  5387. },
  5388.  
  5389. setDockingUnavailable: function(unavailable)
  5390. {
  5391. WebInspector.setDockingUnavailable(unavailable);
  5392. },
  5393.  
  5394. enterInspectElementMode: function()
  5395. {
  5396. WebInspector.toggleSearchingForNode();
  5397. },
  5398.  
  5399. savedURL: function(url)
  5400. {
  5401. WebInspector.fileManager.savedURL(url);
  5402. },
  5403.  
  5404. appendedToURL: function(url)
  5405. {
  5406. WebInspector.fileManager.appendedToURL(url);
  5407. },
  5408.  
  5409. setToolbarColors: function(backgroundColor, color)
  5410. {
  5411. WebInspector.setToolbarColors(backgroundColor, color);
  5412. },
  5413.  
  5414. evaluateForTest: function(callId, script)
  5415. {
  5416. WebInspector.evaluateForTestInFrontend(callId, script);
  5417. },
  5418.  
  5419. dispatch: function(signature)
  5420. {
  5421. if (InspectorFrontendAPI._isLoaded) {
  5422. var methodName = signature.shift();
  5423. return InspectorFrontendAPI[methodName].apply(InspectorFrontendAPI, signature);
  5424. }
  5425. InspectorFrontendAPI._pendingCommands.push(signature);
  5426. },
  5427.  
  5428. dispatchQueryParameters: function()
  5429. {
  5430. if ("dispatch" in WebInspector.queryParamsObject)
  5431. InspectorFrontendAPI.dispatch(JSON.parse(window.decodeURI(WebInspector.queryParamsObject["dispatch"])));
  5432. },
  5433.  
  5434.  
  5435. loadTimelineFromURL: function(url) 
  5436. {
  5437. WebInspector.showPanel("timeline").loadFromURL(url);
  5438. },
  5439.  
  5440. loadCompleted: function()
  5441. {
  5442. InspectorFrontendAPI._isLoaded = true;
  5443. for (var i = 0; i < InspectorFrontendAPI._pendingCommands.length; ++i)
  5444. InspectorFrontendAPI.dispatch(InspectorFrontendAPI._pendingCommands[i]);
  5445. InspectorFrontendAPI._pendingCommands = [];
  5446. if (window.opener)
  5447. window.opener.postMessage(["loadCompleted"], "*");
  5448. },
  5449.  
  5450. contextMenuItemSelected: function(id)
  5451. {
  5452. WebInspector.contextMenuItemSelected(id);
  5453. },
  5454.  
  5455. contextMenuCleared: function()
  5456. {
  5457. WebInspector.contextMenuCleared();
  5458. },
  5459.  
  5460. dispatchMessageAsync: function(messageObject)
  5461. {
  5462. WebInspector.dispatch(messageObject);
  5463. },
  5464.  
  5465. dispatchMessage: function(messageObject)
  5466. {
  5467. InspectorBackend.dispatch(messageObject);
  5468. }
  5469. }
  5470.  
  5471. if (window.opener) {
  5472. function onMessageFromOpener(event)
  5473. {
  5474. if (event.source === window.opener)
  5475. InspectorFrontendAPI.dispatch(event.data);
  5476. }
  5477. window.addEventListener("message", onMessageFromOpener, true);
  5478. }
  5479.  
  5480.  
  5481.  
  5482.  
  5483.  
  5484.  
  5485. WebInspector.Object = function() {
  5486. }
  5487.  
  5488. WebInspector.Object.prototype = {
  5489.  
  5490. addEventListener: function(eventType, listener, thisObject)
  5491. {
  5492. console.assert(listener);
  5493.  
  5494. if (!this._listeners)
  5495. this._listeners = {};
  5496. if (!this._listeners[eventType])
  5497. this._listeners[eventType] = [];
  5498. this._listeners[eventType].push({ thisObject: thisObject, listener: listener });
  5499. },
  5500.  
  5501.  
  5502. removeEventListener: function(eventType, listener, thisObject)
  5503. {
  5504. console.assert(listener);
  5505.  
  5506. if (!this._listeners || !this._listeners[eventType])
  5507. return;
  5508. var listeners = this._listeners[eventType];
  5509. for (var i = 0; i < listeners.length; ++i) {
  5510. if (listener && listeners[i].listener === listener && listeners[i].thisObject === thisObject)
  5511. listeners.splice(i, 1);
  5512. else if (!listener && thisObject && listeners[i].thisObject === thisObject)
  5513. listeners.splice(i, 1);
  5514. }
  5515.  
  5516. if (!listeners.length)
  5517. delete this._listeners[eventType];
  5518. },
  5519.  
  5520. removeAllListeners: function()
  5521. {
  5522. delete this._listeners;
  5523. },
  5524.  
  5525.  
  5526. hasEventListeners: function(eventType)
  5527. {
  5528. if (!this._listeners || !this._listeners[eventType])
  5529. return false;
  5530. return true;
  5531. },
  5532.  
  5533.  
  5534. dispatchEventToListeners: function(eventType, eventData)
  5535. {
  5536. if (!this._listeners || !this._listeners[eventType])
  5537. return false;
  5538.  
  5539. var event = new WebInspector.Event(this, eventType, eventData);
  5540. var listeners = this._listeners[eventType].slice(0);
  5541. for (var i = 0; i < listeners.length; ++i) {
  5542. listeners[i].listener.call(listeners[i].thisObject, event);
  5543. if (event._stoppedPropagation)
  5544. break;
  5545. }
  5546.  
  5547. return event.defaultPrevented;
  5548. }
  5549. }
  5550.  
  5551.  
  5552. WebInspector.Event = function(target, type, data)
  5553. {
  5554. this.target = target;
  5555. this.type = type;
  5556. this.data = data;
  5557. this.defaultPrevented = false;
  5558. this._stoppedPropagation = false;
  5559. }
  5560.  
  5561. WebInspector.Event.prototype = {
  5562. stopPropagation: function()
  5563. {
  5564. this._stoppedPropagation = true;
  5565. },
  5566.  
  5567. preventDefault: function()
  5568. {
  5569. this.defaultPrevented = true;
  5570. },
  5571.  
  5572.  
  5573. consume: function(preventDefault)
  5574. {
  5575. this.stopPropagation();
  5576. if (preventDefault)
  5577. this.preventDefault();
  5578. }
  5579. }
  5580.  
  5581. WebInspector.notifications = new WebInspector.Object();
  5582.  
  5583.  
  5584.  
  5585.  
  5586.  
  5587.  
  5588. var Preferences = {
  5589. maxInlineTextChildLength: 80,
  5590. minConsoleHeight: 75,
  5591. minSidebarWidth: 100,
  5592. minElementsSidebarWidth: 200,
  5593. minScriptsSidebarWidth: 200,
  5594. styleRulesExpandedState: {},
  5595. showMissingLocalizedStrings: false,
  5596. useLowerCaseMenuTitlesOnWindows: false,
  5597. sharedWorkersDebugNote: undefined,
  5598. localizeUI: true,
  5599. exposeDisableCache: false,
  5600. applicationTitle: "Web Inspector - %s",
  5601. showDockToRight: false,
  5602. exposeFileSystemInspection: false,
  5603. experimentsEnabled: true
  5604. }
  5605.  
  5606. var Capabilities = {
  5607. samplingCPUProfiler: false,
  5608. debuggerCausesRecompilation: true,
  5609. separateScriptCompilationAndExecutionEnabled: false,
  5610. profilerCausesRecompilation: true,
  5611. heapProfilerPresent: false,
  5612. canOverrideDeviceMetrics: false,
  5613. timelineSupportsFrameInstrumentation: false,
  5614. timelineCanMonitorMainThread: false,
  5615. canOverrideGeolocation: false,
  5616. canOverrideDeviceOrientation: false,
  5617. canShowFPSCounter: false
  5618. }
  5619.  
  5620.  
  5621. WebInspector.Settings = function()
  5622. {
  5623. this._eventSupport = new WebInspector.Object();
  5624.  
  5625. this.colorFormat = this.createSetting("colorFormat", "original");
  5626. this.consoleHistory = this.createSetting("consoleHistory", []);
  5627. this.debuggerEnabled = this.createSetting("debuggerEnabled", false);
  5628. this.domWordWrap = this.createSetting("domWordWrap", true);
  5629. this.profilerEnabled = this.createSetting("profilerEnabled", false);
  5630. this.eventListenersFilter = this.createSetting("eventListenersFilter", "all");
  5631. this.lastActivePanel = this.createSetting("lastActivePanel", "elements");
  5632. this.lastViewedScriptFile = this.createSetting("lastViewedScriptFile", "application");
  5633. this.monitoringXHREnabled = this.createSetting("monitoringXHREnabled", false);
  5634. this.preserveConsoleLog = this.createSetting("preserveConsoleLog", false);
  5635. this.resourcesLargeRows = this.createSetting("resourcesLargeRows", true);
  5636. this.resourcesSortOptions = this.createSetting("resourcesSortOptions", {timeOption: "responseTime", sizeOption: "transferSize"});
  5637. this.resourceViewTab = this.createSetting("resourceViewTab", "preview");
  5638. this.showInheritedComputedStyleProperties = this.createSetting("showInheritedComputedStyleProperties", false);
  5639. this.showUserAgentStyles = this.createSetting("showUserAgentStyles", true);
  5640. this.watchExpressions = this.createSetting("watchExpressions", []);
  5641. this.breakpoints = this.createSetting("breakpoints", []);
  5642. this.eventListenerBreakpoints = this.createSetting("eventListenerBreakpoints", []);
  5643. this.domBreakpoints = this.createSetting("domBreakpoints", []);
  5644. this.xhrBreakpoints = this.createSetting("xhrBreakpoints", []);
  5645. this.sourceMapsEnabled = this.createSetting("sourceMapsEnabled", false);
  5646. this.cacheDisabled = this.createSetting("cacheDisabled", false);
  5647. this.overrideUserAgent = this.createSetting("overrideUserAgent", "");
  5648. this.userAgent = this.createSetting("userAgent", "");
  5649. this.deviceMetrics = this.createSetting("deviceMetrics", "");
  5650. this.deviceFitWindow = this.createSetting("deviceFitWindow", false);
  5651. this.showScriptFolders = this.createSetting("showScriptFolders", true);
  5652. this.emulateTouchEvents = this.createSetting("emulateTouchEvents", false);
  5653. this.showPaintRects = this.createSetting("showPaintRects", false);
  5654. this.showFPSCounter = this.createSetting("showFPSCounter", false);
  5655. this.showShadowDOM = this.createSetting("showShadowDOM", false);
  5656. this.zoomLevel = this.createSetting("zoomLevel", 0);
  5657. this.savedURLs = this.createSetting("savedURLs", {});
  5658. this.javaScriptDisabled = this.createSetting("javaScriptDisabled", false);
  5659. this.geolocationOverride = this.createSetting("geolocationOverride", "");
  5660. this.deviceOrientationOverride = this.createSetting("deviceOrientationOverride", "");
  5661. this.showHeapSnapshotObjectsHiddenProperties = this.createSetting("showHeaSnapshotObjectsHiddenProperties", false);
  5662. this.showNativeSnapshotUninstrumentedSize = this.createSetting("showNativeSnapshotUninstrumentedSize", false);
  5663. this.searchInContentScripts = this.createSetting("searchInContentScripts", false);
  5664. this.textEditorIndent = this.createSetting("textEditorIndent", "    ");
  5665. this.lastDockState = this.createSetting("lastDockState", "");
  5666. this.cssReloadEnabled = this.createSetting("cssReloadEnabled", false);
  5667. this.cssReloadTimeout = this.createSetting("cssReloadTimeout", 1000);
  5668. this.showCpuOnTimelineRuler = this.createSetting("showCpuOnTimelineRuler", false);
  5669. this.showMetricsRulers = this.createSetting("showMetricsRulers", false);
  5670. this.emulatedCSSMedia = this.createSetting("emulatedCSSMedia", "print");
  5671. this.showToolbarIcons = this.createSetting("showToolbarIcons", false);
  5672.  
  5673.  
  5674.  
  5675. if (this.breakpoints.get().length > 500000)
  5676. this.breakpoints.set([]);
  5677. }
  5678.  
  5679. WebInspector.Settings.prototype = {
  5680.  
  5681. createSetting: function(key, defaultValue)
  5682. {
  5683. return new WebInspector.Setting(key, defaultValue, this._eventSupport);
  5684. }
  5685. }
  5686.  
  5687.  
  5688. WebInspector.Setting = function(name, defaultValue, eventSupport)
  5689. {
  5690. this._name = name;
  5691. this._defaultValue = defaultValue;
  5692. this._eventSupport = eventSupport;
  5693. }
  5694.  
  5695. WebInspector.Setting.prototype = {
  5696. addChangeListener: function(listener, thisObject)
  5697. {
  5698. this._eventSupport.addEventListener(this._name, listener, thisObject);
  5699. },
  5700.  
  5701. removeChangeListener: function(listener, thisObject)
  5702. {
  5703. this._eventSupport.removeEventListener(this._name, listener, thisObject);
  5704. },
  5705.  
  5706. get name()
  5707. {
  5708. return this._name;
  5709. },
  5710.  
  5711. get: function()
  5712. {
  5713. if (typeof this._value !== "undefined")
  5714. return this._value;
  5715.  
  5716. this._value = this._defaultValue;
  5717. if (window.localStorage != null && this._name in window.localStorage) {
  5718. try {
  5719. this._value = JSON.parse(window.localStorage[this._name]);
  5720. } catch(e) {
  5721. window.localStorage.removeItem(this._name);
  5722. }
  5723. }
  5724. return this._value;
  5725. },
  5726.  
  5727. set: function(value)
  5728. {
  5729. this._value = value;
  5730. if (window.localStorage != null) {
  5731. try {
  5732. window.localStorage[this._name] = JSON.stringify(value);
  5733. } catch(e) {
  5734. console.error("Error saving setting with name:" + this._name);
  5735. }
  5736. }
  5737. this._eventSupport.dispatchEventToListeners(this._name, value);
  5738. }
  5739. }
  5740.  
  5741.  
  5742. WebInspector.ExperimentsSettings = function()
  5743. {
  5744. this._setting = WebInspector.settings.createSetting("experiments", {});
  5745. this._experiments = [];
  5746. this._enabledForTest = {};
  5747.  
  5748.  
  5749. this.snippetsSupport = this._createExperiment("snippetsSupport", "Snippets support");
  5750. this.nativeMemorySnapshots = this._createExperiment("nativeMemorySnapshots", "Native memory profiling");
  5751. this.liveNativeMemoryChart = this._createExperiment("liveNativeMemoryChart", "Live native memory chart");
  5752. this.fileSystemInspection = this._createExperiment("fileSystemInspection", "FileSystem inspection");
  5753. this.canvasInspection = this._createExperiment("canvasInspection ", "Canvas inspection");
  5754. this.sass = this._createExperiment("sass", "Support for Sass");
  5755. this.codemirror = this._createExperiment("codemirror", "Use CodeMirror editor");
  5756. this.cssRegions = this._createExperiment("cssRegions", "CSS Regions Support");
  5757. this.showOverridesInDrawer = this._createExperiment("showOverridesInDrawer", "Show Overrides in drawer");
  5758.  
  5759. this._cleanUpSetting();
  5760. }
  5761.  
  5762. WebInspector.ExperimentsSettings.prototype = {
  5763.  
  5764. get experiments()
  5765. {
  5766. return this._experiments.slice();
  5767. },
  5768.  
  5769.  
  5770. get experimentsEnabled()
  5771. {
  5772. return Preferences.experimentsEnabled || ("experiments" in WebInspector.queryParamsObject);
  5773. },
  5774.  
  5775.  
  5776. _createExperiment: function(experimentName, experimentTitle)
  5777. {
  5778. var experiment = new WebInspector.Experiment(this, experimentName, experimentTitle);
  5779. this._experiments.push(experiment);
  5780. return experiment;
  5781. },
  5782.  
  5783.  
  5784. isEnabled: function(experimentName)
  5785. {
  5786. if (this._enabledForTest[experimentName])
  5787. return true;
  5788.  
  5789. if (!this.experimentsEnabled)
  5790. return false;
  5791.  
  5792. var experimentsSetting = this._setting.get();
  5793. return experimentsSetting[experimentName];
  5794. },
  5795.  
  5796.  
  5797. setEnabled: function(experimentName, enabled)
  5798. {
  5799. var experimentsSetting = this._setting.get();
  5800. experimentsSetting[experimentName] = enabled;
  5801. this._setting.set(experimentsSetting);
  5802. },
  5803.  
  5804.  
  5805. _enableForTest: function(experimentName)
  5806. {
  5807. this._enabledForTest[experimentName] = true;
  5808. },
  5809.  
  5810. _cleanUpSetting: function()
  5811. {
  5812. var experimentsSetting = this._setting.get();
  5813. var cleanedUpExperimentSetting = {};
  5814. for (var i = 0; i < this._experiments.length; ++i) {
  5815. var experimentName = this._experiments[i].name;
  5816. if (experimentsSetting[experimentName])
  5817. cleanedUpExperimentSetting[experimentName] = true;
  5818. }
  5819. this._setting.set(cleanedUpExperimentSetting);
  5820. }
  5821. }
  5822.  
  5823.  
  5824. WebInspector.Experiment = function(experimentsSettings, name, title)
  5825. {
  5826. this._name = name;
  5827. this._title = title;
  5828. this._experimentsSettings = experimentsSettings;
  5829. }
  5830.  
  5831. WebInspector.Experiment.prototype = {
  5832.  
  5833. get name()
  5834. {
  5835. return this._name;
  5836. },
  5837.  
  5838.  
  5839. get title()
  5840. {
  5841. return this._title;
  5842. },
  5843.  
  5844.  
  5845. isEnabled: function()
  5846. {
  5847. return this._experimentsSettings.isEnabled(this._name);
  5848. },
  5849.  
  5850.  
  5851. setEnabled: function(enabled)
  5852. {
  5853. return this._experimentsSettings.setEnabled(this._name, enabled);
  5854. },
  5855.  
  5856. enableForTest: function()
  5857. {
  5858. this._experimentsSettings._enableForTest(this._name);
  5859. }
  5860. }
  5861.  
  5862. WebInspector.settings = new WebInspector.Settings();
  5863. WebInspector.experimentsSettings = new WebInspector.ExperimentsSettings();
  5864.  
  5865.  
  5866.  
  5867.  
  5868.  
  5869.  
  5870. WebInspector.View = function()
  5871. {
  5872. this.element = document.createElement("div");
  5873. this.element.__view = this;
  5874. this._visible = true;
  5875. this._isRoot = false;
  5876. this._isShowing = false;
  5877. this._children = [];
  5878. this._hideOnDetach = false;
  5879. this._cssFiles = [];
  5880. this._notificationDepth = 0;
  5881. }
  5882.  
  5883. WebInspector.View._cssFileToVisibleViewCount = {};
  5884. WebInspector.View._cssFileToStyleElement = {};
  5885.  
  5886. WebInspector.View.prototype = {
  5887. markAsRoot: function()
  5888. {
  5889. this._isRoot = true;
  5890. },
  5891.  
  5892. isShowing: function()
  5893. {
  5894. return this._isShowing;
  5895. },
  5896.  
  5897. setHideOnDetach: function()
  5898. {
  5899. this._hideOnDetach = true;
  5900. },
  5901.  
  5902.  
  5903. _inNotification: function()
  5904. {
  5905. return !!this._notificationDepth || (this._parentView && this._parentView._inNotification());
  5906. },
  5907.  
  5908. _parentIsShowing: function()
  5909. {
  5910. if (this._isRoot)
  5911. return true;
  5912. return this._parentView && this._parentView.isShowing();
  5913. },
  5914.  
  5915.  
  5916. _callOnVisibleChildren: function(method)
  5917. {
  5918. var copy = this._children.slice();
  5919. for (var i = 0; i < copy.length; ++i) {
  5920. if (copy[i]._parentView === this && copy[i]._visible)
  5921. method.call(copy[i]);
  5922. }
  5923. },
  5924.  
  5925. _processWillShow: function()
  5926. {
  5927. this._loadCSSIfNeeded();
  5928. this._callOnVisibleChildren(this._processWillShow);
  5929. },
  5930.  
  5931. _processWasShown: function()
  5932. {
  5933. if (this._inNotification())
  5934. return;
  5935. this._isShowing = true;
  5936. this.restoreScrollPositions();
  5937. this._notify(this.wasShown);
  5938. this._notify(this.onResize);
  5939. this._callOnVisibleChildren(this._processWasShown);
  5940. },
  5941.  
  5942. _processWillHide: function()
  5943. {
  5944. if (this._inNotification())
  5945. return;
  5946. this.storeScrollPositions();
  5947.  
  5948. this._callOnVisibleChildren(this._processWillHide);
  5949. this._notify(this.willHide);
  5950. this._isShowing = false;
  5951. },
  5952.  
  5953. _processWasHidden: function()
  5954. {
  5955. this._disableCSSIfNeeded();
  5956. this._callOnVisibleChildren(this._processWasHidden);
  5957. },
  5958.  
  5959. _processOnResize: function()
  5960. {
  5961. if (this._inNotification())
  5962. return;
  5963. if (!this.isShowing())
  5964. return;
  5965. this._notify(this.onResize);
  5966. this._callOnVisibleChildren(this._processOnResize);
  5967. },
  5968.  
  5969.  
  5970. _notify: function(notification)
  5971. {
  5972. ++this._notificationDepth;
  5973. try {
  5974. notification.call(this);
  5975. } finally {
  5976. --this._notificationDepth;
  5977. }
  5978. },
  5979.  
  5980. wasShown: function()
  5981. {
  5982. },
  5983.  
  5984. willHide: function()
  5985. {
  5986. },
  5987.  
  5988. onResize: function()
  5989. {
  5990. },
  5991.  
  5992.  
  5993. show: function(parentElement, insertBefore)
  5994. {
  5995. WebInspector.View._assert(parentElement, "Attempt to attach view with no parent element");
  5996.  
  5997.  
  5998. if (this.element.parentElement !== parentElement) {
  5999. if (this.element.parentElement)
  6000. this.detach();
  6001.  
  6002. var currentParent = parentElement;
  6003. while (currentParent && !currentParent.__view)
  6004. currentParent = currentParent.parentElement;
  6005.  
  6006. if (currentParent) {
  6007. this._parentView = currentParent.__view;
  6008. this._parentView._children.push(this);
  6009. this._isRoot = false;
  6010. } else
  6011. WebInspector.View._assert(this._isRoot, "Attempt to attach view to orphan node");
  6012. } else if (this._visible)
  6013. return;
  6014.  
  6015. this._visible = true;
  6016.  
  6017. if (this._parentIsShowing())
  6018. this._processWillShow();
  6019.  
  6020. this.element.addStyleClass("visible");
  6021.  
  6022.  
  6023. if (this.element.parentElement !== parentElement) {
  6024. WebInspector.View._incrementViewCounter(parentElement, this.element);
  6025. if (insertBefore)
  6026. WebInspector.View._originalInsertBefore.call(parentElement, this.element, insertBefore);
  6027. else
  6028. WebInspector.View._originalAppendChild.call(parentElement, this.element);
  6029. }
  6030.  
  6031. if (this._parentIsShowing())
  6032. this._processWasShown();
  6033. },
  6034.  
  6035.  
  6036. detach: function(overrideHideOnDetach)
  6037. {
  6038. var parentElement = this.element.parentElement;
  6039. if (!parentElement)
  6040. return;
  6041.  
  6042. if (this._parentIsShowing())
  6043. this._processWillHide();
  6044.  
  6045. if (this._hideOnDetach && !overrideHideOnDetach) {
  6046. this.element.removeStyleClass("visible");
  6047. this._visible = false;
  6048. if (this._parentIsShowing())
  6049. this._processWasHidden();
  6050. return;
  6051. }
  6052.  
  6053.  
  6054. WebInspector.View._decrementViewCounter(parentElement, this.element);
  6055. WebInspector.View._originalRemoveChild.call(parentElement, this.element);
  6056.  
  6057. this._visible = false;
  6058. if (this._parentIsShowing())
  6059. this._processWasHidden();
  6060.  
  6061.  
  6062. if (this._parentView) {
  6063. var childIndex = this._parentView._children.indexOf(this);
  6064. WebInspector.View._assert(childIndex >= 0, "Attempt to remove non-child view");
  6065. this._parentView._children.splice(childIndex, 1);
  6066. this._parentView = null;
  6067. } else
  6068. WebInspector.View._assert(this._isRoot, "Removing non-root view from DOM");
  6069. },
  6070.  
  6071. detachChildViews: function()
  6072. {
  6073. var children = this._children.slice();
  6074. for (var i = 0; i < children.length; ++i)
  6075. children[i].detach();
  6076. },
  6077.  
  6078. elementsToRestoreScrollPositionsFor: function()
  6079. {
  6080. return [this.element];
  6081. },
  6082.  
  6083. storeScrollPositions: function()
  6084. {
  6085. var elements = this.elementsToRestoreScrollPositionsFor();
  6086. for (var i = 0; i < elements.length; ++i) {
  6087. var container = elements[i];
  6088. container._scrollTop = container.scrollTop;
  6089. container._scrollLeft = container.scrollLeft;
  6090. }
  6091. },
  6092.  
  6093. restoreScrollPositions: function()
  6094. {
  6095. var elements = this.elementsToRestoreScrollPositionsFor();
  6096. for (var i = 0; i < elements.length; ++i) {
  6097. var container = elements[i];
  6098. if (container._scrollTop)
  6099. container.scrollTop = container._scrollTop;
  6100. if (container._scrollLeft)
  6101. container.scrollLeft = container._scrollLeft;
  6102. }
  6103. },
  6104.  
  6105. canHighlightLine: function()
  6106. {
  6107. return false;
  6108. },
  6109.  
  6110. highlightLine: function(line)
  6111. {
  6112. },
  6113.  
  6114. doResize: function()
  6115. {
  6116. this._processOnResize();
  6117. },
  6118.  
  6119. registerRequiredCSS: function(cssFile)
  6120. {
  6121. this._cssFiles.push(cssFile);
  6122. },
  6123.  
  6124. _loadCSSIfNeeded: function()
  6125. {
  6126. for (var i = 0; i < this._cssFiles.length; ++i) {
  6127. var cssFile = this._cssFiles[i];
  6128.  
  6129. var viewsWithCSSFile = WebInspector.View._cssFileToVisibleViewCount[cssFile];
  6130. WebInspector.View._cssFileToVisibleViewCount[cssFile] = (viewsWithCSSFile || 0) + 1;
  6131. if (!viewsWithCSSFile)
  6132. this._doLoadCSS(cssFile);
  6133. }
  6134. },
  6135.  
  6136. _doLoadCSS: function(cssFile)
  6137. {
  6138. var styleElement = WebInspector.View._cssFileToStyleElement[cssFile];
  6139. if (styleElement) {
  6140. styleElement.disabled = false;
  6141. return;
  6142. }
  6143.  
  6144. if (window.debugCSS) {  
  6145. styleElement = document.createElement("link");
  6146. styleElement.rel = "stylesheet";
  6147. styleElement.type = "text/css";
  6148. styleElement.href = cssFile;
  6149. } else {
  6150. var xhr = new XMLHttpRequest();
  6151. xhr.open("GET", cssFile, false);
  6152. xhr.send(null);
  6153.  
  6154. styleElement = document.createElement("style");
  6155. styleElement.type = "text/css";
  6156. styleElement.textContent = xhr.responseText;
  6157. }
  6158. document.head.insertBefore(styleElement, document.head.firstChild);
  6159.  
  6160. WebInspector.View._cssFileToStyleElement[cssFile] = styleElement;
  6161. },
  6162.  
  6163. _disableCSSIfNeeded: function()
  6164. {
  6165. for (var i = 0; i < this._cssFiles.length; ++i) {
  6166. var cssFile = this._cssFiles[i];
  6167.  
  6168. var viewsWithCSSFile = WebInspector.View._cssFileToVisibleViewCount[cssFile];
  6169. viewsWithCSSFile--;
  6170. WebInspector.View._cssFileToVisibleViewCount[cssFile] = viewsWithCSSFile;
  6171.  
  6172. if (!viewsWithCSSFile)
  6173. this._doUnloadCSS(cssFile);
  6174. }
  6175. },
  6176.  
  6177. _doUnloadCSS: function(cssFile)
  6178. {
  6179. var styleElement = WebInspector.View._cssFileToStyleElement[cssFile];
  6180. styleElement.disabled = true;
  6181. },
  6182.  
  6183. printViewHierarchy: function()
  6184. {
  6185. var lines = [];
  6186. this._collectViewHierarchy("", lines);
  6187. console.log(lines.join("\n"));
  6188. },
  6189.  
  6190. _collectViewHierarchy: function(prefix, lines)
  6191. {
  6192. lines.push(prefix + "[" + this.element.className + "]" + (this._children.length ? " {" : ""));
  6193.  
  6194. for (var i = 0; i < this._children.length; ++i)
  6195. this._children[i]._collectViewHierarchy(prefix + "    ", lines);
  6196.  
  6197. if (this._children.length)
  6198. lines.push(prefix + "}");
  6199. },
  6200.  
  6201.  
  6202. defaultFocusedElement: function()
  6203. {
  6204. return this._defaultFocusedElement || this.element;
  6205. },
  6206.  
  6207.  
  6208. setDefaultFocusedElement: function(element)
  6209. {
  6210. this._defaultFocusedElement = element;
  6211. },
  6212.  
  6213. focus: function()
  6214. {
  6215. var element = this.defaultFocusedElement();
  6216. if (!element || element.isAncestor(document.activeElement))
  6217. return;
  6218.  
  6219. WebInspector.setCurrentFocusElement(element);
  6220. },
  6221.  
  6222.  
  6223. measurePreferredSize: function()
  6224. {
  6225. this._loadCSSIfNeeded();
  6226. WebInspector.View._originalAppendChild.call(document.body, this.element);
  6227. this.element.positionAt(0, 0);
  6228. var result = new Size(this.element.offsetWidth, this.element.offsetHeight);
  6229. this.element.positionAt(undefined, undefined);
  6230. WebInspector.View._originalRemoveChild.call(document.body, this.element);
  6231. this._disableCSSIfNeeded();
  6232. return result;
  6233. },
  6234.  
  6235. __proto__: WebInspector.Object.prototype
  6236. }
  6237.  
  6238. WebInspector.View._originalAppendChild = Element.prototype.appendChild;
  6239. WebInspector.View._originalInsertBefore = Element.prototype.insertBefore;
  6240. WebInspector.View._originalRemoveChild = Element.prototype.removeChild;
  6241. WebInspector.View._originalRemoveChildren = Element.prototype.removeChildren;
  6242.  
  6243. WebInspector.View._incrementViewCounter = function(parentElement, childElement)
  6244. {
  6245. var count = (childElement.__viewCounter || 0) + (childElement.__view ? 1 : 0);
  6246. if (!count)
  6247. return;
  6248.  
  6249. while (parentElement) {
  6250. parentElement.__viewCounter = (parentElement.__viewCounter || 0) + count;
  6251. parentElement = parentElement.parentElement;
  6252. }
  6253. }
  6254.  
  6255. WebInspector.View._decrementViewCounter = function(parentElement, childElement)
  6256. {
  6257. var count = (childElement.__viewCounter || 0) + (childElement.__view ? 1 : 0);
  6258. if (!count)
  6259. return;
  6260.  
  6261. while (parentElement) {
  6262. parentElement.__viewCounter -= count;
  6263. parentElement = parentElement.parentElement;
  6264. }
  6265. }
  6266.  
  6267. WebInspector.View._assert = function(condition, message)
  6268. {
  6269. if (!condition) {
  6270. console.trace();
  6271. throw new Error(message);
  6272. }
  6273. }
  6274.  
  6275. Element.prototype.appendChild = function(child)
  6276. {
  6277. WebInspector.View._assert(!child.__view, "Attempt to add view via regular DOM operation.");
  6278. return WebInspector.View._originalAppendChild.call(this, child);
  6279. }
  6280.  
  6281. Element.prototype.insertBefore = function(child, anchor)
  6282. {
  6283. WebInspector.View._assert(!child.__view, "Attempt to add view via regular DOM operation.");
  6284. return WebInspector.View._originalInsertBefore.call(this, child, anchor);
  6285. }
  6286.  
  6287.  
  6288. Element.prototype.removeChild = function(child)
  6289. {
  6290. WebInspector.View._assert(!child.__viewCounter && !child.__view, "Attempt to remove element containing view via regular DOM operation");
  6291. return WebInspector.View._originalRemoveChild.call(this, child);
  6292. }
  6293.  
  6294. Element.prototype.removeChildren = function()
  6295. {
  6296. WebInspector.View._assert(!this.__viewCounter, "Attempt to remove element containing view via regular DOM operation");
  6297. WebInspector.View._originalRemoveChildren.call(this);
  6298. }
  6299.  
  6300.  
  6301.  
  6302.  
  6303.  
  6304.  
  6305. WebInspector.HelpScreen = function(title)
  6306. {
  6307. WebInspector.View.call(this);
  6308. this.markAsRoot();
  6309. this.registerRequiredCSS("helpScreen.css");
  6310.  
  6311. this.element.className = "help-window-outer";
  6312. this.element.addEventListener("keydown", this._onKeyDown.bind(this), false);
  6313. this.element.tabIndex = 0;
  6314. this.element.addEventListener("focus", this._onBlur.bind(this), false);
  6315.  
  6316. if (title) {
  6317. var mainWindow = this.element.createChild("div", "help-window-main");
  6318. var captionWindow = mainWindow.createChild("div", "help-window-caption");
  6319. captionWindow.appendChild(this._createCloseButton());
  6320. this.contentElement = mainWindow.createChild("div", "help-content");
  6321. captionWindow.createChild("h1", "help-window-title").textContent = title;
  6322. }
  6323. }
  6324.  
  6325.  
  6326. WebInspector.HelpScreen._visibleScreen = null;
  6327.  
  6328. WebInspector.HelpScreen.prototype = {
  6329. _createCloseButton: function()
  6330. {
  6331. var closeButton = document.createElement("button");
  6332. closeButton.className = "help-close-button";
  6333. closeButton.textContent = "\u2716"; 
  6334. closeButton.addEventListener("click", this.hide.bind(this), false);
  6335. return closeButton;
  6336. },
  6337.  
  6338. showModal: function()
  6339. {
  6340. var visibleHelpScreen = WebInspector.HelpScreen._visibleScreen;
  6341. if (visibleHelpScreen === this)
  6342. return;
  6343.  
  6344. if (visibleHelpScreen)
  6345. visibleHelpScreen.hide();
  6346. WebInspector.HelpScreen._visibleScreen = this;
  6347. this.show(document.body);
  6348. this.focus();
  6349. },
  6350.  
  6351. hide: function()
  6352. {
  6353. if (!this.isShowing())
  6354. return;
  6355.  
  6356. WebInspector.HelpScreen._visibleScreen = null;
  6357.  
  6358. WebInspector.restoreFocusFromElement(this.element);
  6359. this.detach();
  6360. },
  6361.  
  6362.  
  6363. isClosingKey: function(keyCode)
  6364. {
  6365. return [
  6366. WebInspector.KeyboardShortcut.Keys.Enter.code,
  6367. WebInspector.KeyboardShortcut.Keys.Esc.code,
  6368. WebInspector.KeyboardShortcut.Keys.Space.code,
  6369. ].indexOf(keyCode) >= 0;
  6370. },
  6371.  
  6372. _onKeyDown: function(event)
  6373. {
  6374. if (this.isShowing() && this.isClosingKey(event.keyCode)) {
  6375. this.hide();
  6376. event.consume();
  6377. }
  6378. },
  6379.  
  6380. _onBlur: function(event)
  6381. {
  6382.  
  6383. if (this.isShowing() && !this.element.isSelfOrAncestor(event.target))
  6384. WebInspector.setCurrentFocusElement(this.element);
  6385. },
  6386.  
  6387. __proto__: WebInspector.View.prototype
  6388. }
  6389.  
  6390.  
  6391.  
  6392.  
  6393.  
  6394. if (!window.InspectorFrontendHost) {
  6395.  
  6396.  
  6397. WebInspector.InspectorFrontendHostStub = function()
  6398. {
  6399. this._attachedWindowHeight = 0;
  6400. this.isStub = true;
  6401. this._fileBuffers = {};
  6402. WebInspector.documentCopyEventFired = this.documentCopy.bind(this);
  6403. }
  6404.  
  6405. WebInspector.InspectorFrontendHostStub.prototype = {
  6406. platform: function()
  6407. {
  6408. var match = navigator.userAgent.match(/Windows NT/);
  6409. if (match)
  6410. return "windows";
  6411. match = navigator.userAgent.match(/Mac OS X/);
  6412. if (match)
  6413. return "mac";
  6414. return "linux";
  6415. },
  6416.  
  6417. port: function()
  6418. {
  6419. return "unknown";
  6420. },
  6421.  
  6422. bringToFront: function()
  6423. {
  6424. this._windowVisible = true;
  6425. },
  6426.  
  6427. closeWindow: function()
  6428. {
  6429. this._windowVisible = false;
  6430. },
  6431.  
  6432. requestSetDockSide: function(side)
  6433. {
  6434. InspectorFrontendAPI.setDockSide(side);
  6435. },
  6436.  
  6437. setAttachedWindowHeight: function(height)
  6438. {
  6439. },
  6440.  
  6441. moveWindowBy: function(x, y)
  6442. {
  6443. },
  6444.  
  6445. setInjectedScriptForOrigin: function(origin, script)
  6446. {
  6447. },
  6448.  
  6449. loaded: function()
  6450. {
  6451. },
  6452.  
  6453. localizedStringsURL: function()
  6454. {
  6455. return undefined;
  6456. },
  6457.  
  6458. hiddenPanels: function()
  6459. {
  6460. return WebInspector.queryParamsObject["hiddenPanels"] || "";
  6461. },
  6462.  
  6463. inspectedURLChanged: function(url)
  6464. {
  6465. document.title = WebInspector.UIString(Preferences.applicationTitle, url);
  6466. },
  6467.  
  6468. documentCopy: function(event)
  6469. {
  6470. if (!this._textToCopy)
  6471. return;
  6472. event.clipboardData.setData("text", this._textToCopy);
  6473. event.preventDefault();
  6474. delete this._textToCopy;
  6475. },
  6476.  
  6477. copyText: function(text)
  6478. {
  6479. this._textToCopy = text;
  6480. if (!document.execCommand("copy")) {
  6481. var screen = new WebInspector.ClipboardAccessDeniedScreen();
  6482. screen.showModal();
  6483. }
  6484. },
  6485.  
  6486. openInNewTab: function(url)
  6487. {
  6488. window.open(url, "_blank");
  6489. },
  6490.  
  6491. canSave: function()
  6492. {
  6493. return true;
  6494. },
  6495.  
  6496. save: function(url, content, forceSaveAs)
  6497. {
  6498. if (this._fileBuffers[url])
  6499. throw new Error("Concurrent file modification denied.");
  6500.  
  6501. this._fileBuffers[url] = [content];
  6502. setTimeout(WebInspector.fileManager.savedURL.bind(WebInspector.fileManager, url), 0);
  6503. },
  6504.  
  6505. append: function(url, content)
  6506. {
  6507. var buffer = this._fileBuffers[url];
  6508. if (!buffer)
  6509. throw new Error("File is not open for write yet.");
  6510.  
  6511. buffer.push(content);
  6512. setTimeout(WebInspector.fileManager.appendedToURL.bind(WebInspector.fileManager, url), 0);
  6513. },
  6514.  
  6515. close: function(url)
  6516. {
  6517. var content = this._fileBuffers[url];
  6518. delete this._fileBuffers[url];
  6519.  
  6520. if (!content)
  6521. return;
  6522.  
  6523. var lastSlashIndex = url.lastIndexOf("/");
  6524. var fileNameSuffix = (lastSlashIndex === -1) ? url : url.substring(lastSlashIndex + 1);
  6525.  
  6526. var blob = new Blob(content, { type: "application/octet-stream" });
  6527. var objectUrl = window.URL.createObjectURL(blob);
  6528. window.location = objectUrl + "#" + fileNameSuffix;
  6529.  
  6530. function cleanup()
  6531. {
  6532. window.URL.revokeObjectURL(objectUrl);
  6533. }
  6534. setTimeout(cleanup, 0);
  6535. },
  6536.  
  6537. sendMessageToBackend: function(message)
  6538. {
  6539. },
  6540.  
  6541. recordActionTaken: function(actionCode)
  6542. {
  6543. },
  6544.  
  6545. recordPanelShown: function(panelCode)
  6546. {
  6547. },
  6548.  
  6549. recordSettingChanged: function(settingCode)
  6550. {
  6551. },
  6552.  
  6553. loadResourceSynchronously: function(url)
  6554. {
  6555. return loadXHR(url);
  6556. },
  6557.  
  6558. setZoomFactor: function(zoom)
  6559. {
  6560. },
  6561.  
  6562. canInspectWorkers: function()
  6563. {
  6564. return true;
  6565. },
  6566.  
  6567. isUnderTest: function()
  6568. {
  6569. return false;
  6570. }
  6571. }
  6572.  
  6573. InspectorFrontendHost = new WebInspector.InspectorFrontendHostStub();
  6574. Preferences.localizeUI = false;
  6575.  
  6576.  
  6577. WebInspector.clipboardAccessDeniedMessage = function()
  6578. {
  6579. return "";
  6580. }
  6581.  
  6582.  
  6583. WebInspector.ClipboardAccessDeniedScreen = function()
  6584. {
  6585. WebInspector.HelpScreen.call(this, WebInspector.UIString("Clipboard access is denied"));
  6586. var platformMessage = WebInspector.clipboardAccessDeniedMessage();
  6587. if (platformMessage) {
  6588. var p = this.contentElement.createChild("p");
  6589. p.addStyleClass("help-section");
  6590. p.textContent = platformMessage;
  6591. }
  6592. }
  6593.  
  6594. WebInspector.ClipboardAccessDeniedScreen.prototype = {
  6595. __proto__: WebInspector.HelpScreen.prototype
  6596. }
  6597.  
  6598. }
  6599.  
  6600.  
  6601. WebInspector.RemoteDebuggingTerminatedScreen = function(reason)
  6602. {
  6603. WebInspector.HelpScreen.call(this, WebInspector.UIString("Detached from the target"));
  6604. var p = this.contentElement.createChild("p");
  6605. p.addStyleClass("help-section");
  6606. p.createChild("span").textContent = "Remote debugging has been terminated with reason: ";
  6607. p.createChild("span", "error-message").textContent = reason;
  6608. p.createChild("br");
  6609. p.createChild("span").textContent = "Please re-attach to the new target.";
  6610. }
  6611.  
  6612. WebInspector.RemoteDebuggingTerminatedScreen.prototype = {
  6613. __proto__: WebInspector.HelpScreen.prototype
  6614. }
  6615.  
  6616.  
  6617.  
  6618.  
  6619.  
  6620.  
  6621. WebInspector.FileManager = function()
  6622. {
  6623. }
  6624.  
  6625. WebInspector.FileManager.EventTypes = {
  6626. SavedURL: "SavedURL",
  6627. AppendedToURL: "AppendedToURL"
  6628. }
  6629.  
  6630. WebInspector.FileManager.prototype = {
  6631.  
  6632. canSave: function()
  6633. {
  6634. return InspectorFrontendHost.canSave();
  6635. },
  6636.  
  6637.  
  6638. save: function(url, content, forceSaveAs)
  6639. {
  6640.  
  6641. var savedURLs = WebInspector.settings.savedURLs.get();
  6642. delete savedURLs[url];
  6643. WebInspector.settings.savedURLs.set(savedURLs);
  6644. InspectorFrontendHost.save(url, content, forceSaveAs);
  6645. },
  6646.  
  6647.  
  6648. savedURL: function(url)
  6649. {
  6650. var savedURLs = WebInspector.settings.savedURLs.get();
  6651. savedURLs[url] = true;
  6652. WebInspector.settings.savedURLs.set(savedURLs);
  6653. this.dispatchEventToListeners(WebInspector.FileManager.EventTypes.SavedURL, url);
  6654. },
  6655.  
  6656.  
  6657. isURLSaved: function(url)
  6658. {
  6659. var savedURLs = WebInspector.settings.savedURLs.get();
  6660. return savedURLs[url];
  6661. },
  6662.  
  6663.  
  6664. append: function(url, content)
  6665. {
  6666. InspectorFrontendHost.append(url, content);
  6667. },
  6668.  
  6669.  
  6670. close: function(url)
  6671. {
  6672. InspectorFrontendHost.close(url);
  6673. },
  6674.  
  6675.  
  6676. appendedToURL: function(url)
  6677. {
  6678. this.dispatchEventToListeners(WebInspector.FileManager.EventTypes.AppendedToURL, url);
  6679. },
  6680.  
  6681. __proto__: WebInspector.Object.prototype
  6682. }
  6683.  
  6684. WebInspector.fileManager = new WebInspector.FileManager();
  6685.  
  6686.  
  6687.  
  6688.  
  6689.  
  6690.  
  6691. WebInspector.Checkbox = function(label, className, tooltip)
  6692. {
  6693. this.element = document.createElement('label');
  6694. this._inputElement = document.createElement('input');
  6695. this._inputElement.type = "checkbox";
  6696.  
  6697. this.element.className = className;
  6698. this.element.appendChild(this._inputElement);
  6699. this.element.appendChild(document.createTextNode(label));
  6700. if (tooltip)
  6701. this.element.title = tooltip;
  6702. }
  6703.  
  6704. WebInspector.Checkbox.prototype = {
  6705. set checked(checked)
  6706. {
  6707. this._inputElement.checked = checked;
  6708. },
  6709.  
  6710. get checked()
  6711. {
  6712. return this._inputElement.checked;
  6713. },
  6714.  
  6715. addEventListener: function(listener)
  6716. {
  6717. function listenerWrapper(event)
  6718. {
  6719. if (listener)
  6720. listener(event);
  6721. event.consume();
  6722. return true;
  6723. }
  6724.  
  6725. this._inputElement.addEventListener("click", listenerWrapper, false);
  6726. this.element.addEventListener("click", listenerWrapper, false);
  6727. }
  6728. }
  6729.  
  6730.  
  6731.  
  6732.  
  6733.  
  6734.  
  6735. WebInspector.ContextMenuItem = function(topLevelMenu, type, label, disabled, checked)
  6736. {
  6737. this._type = type;
  6738. this._label = label;
  6739. this._disabled = disabled;
  6740. this._checked = checked;
  6741. this._contextMenu = topLevelMenu;
  6742. if (type === "item" || type === "checkbox")
  6743. this._id = topLevelMenu.nextId();
  6744. }
  6745.  
  6746. WebInspector.ContextMenuItem.prototype = {
  6747. id: function()
  6748. {
  6749. return this._id;
  6750. },
  6751.  
  6752. type: function()
  6753. {
  6754. return this._type;
  6755. },
  6756.  
  6757. _buildDescriptor: function()
  6758. {
  6759. switch (this._type) {
  6760. case "item":
  6761. return { type: "item", id: this._id, label: this._label, enabled: !this._disabled };
  6762. case "separator":
  6763. return { type: "separator" };
  6764. case "checkbox":
  6765. return { type: "checkbox", id: this._id, label: this._label, checked: !!this._checked, enabled: !this._disabled };
  6766. }
  6767. }
  6768. }
  6769.  
  6770.  
  6771. WebInspector.ContextSubMenuItem = function(topLevelMenu, label, disabled)
  6772. {
  6773. WebInspector.ContextMenuItem.call(this, topLevelMenu, "subMenu", label, disabled);
  6774. this._items = [];
  6775. }
  6776.  
  6777. WebInspector.ContextSubMenuItem.prototype = {
  6778.  
  6779. appendItem: function(label, handler, disabled)
  6780. {
  6781. var item = new WebInspector.ContextMenuItem(this._contextMenu, "item", label, disabled);
  6782. this._pushItem(item);
  6783. this._contextMenu._setHandler(item.id(), handler);
  6784. return item;
  6785. },
  6786.  
  6787. appendSubMenuItem: function(label, disabled)
  6788. {
  6789. var item = new WebInspector.ContextSubMenuItem(this._contextMenu, label, disabled);
  6790. this._pushItem(item);
  6791. return item;
  6792. },
  6793.  
  6794.  
  6795. appendCheckboxItem: function(label, handler, checked, disabled)
  6796. {
  6797. var item = new WebInspector.ContextMenuItem(this._contextMenu, "checkbox", label, disabled, checked);
  6798. this._pushItem(item);
  6799. this._contextMenu._setHandler(item.id(), handler);
  6800. return item;
  6801. },
  6802.  
  6803. appendSeparator: function()
  6804. {
  6805. if (this._items.length)
  6806. this._pendingSeparator = true;
  6807. },
  6808.  
  6809. _pushItem: function(item)
  6810. {
  6811. if (this._pendingSeparator) {
  6812. this._items.push(new WebInspector.ContextMenuItem(this._contextMenu, "separator"));
  6813. delete this._pendingSeparator;
  6814. }
  6815. this._items.push(item);
  6816. },
  6817.  
  6818.  
  6819. isEmpty: function()
  6820. {
  6821. return !this._items.length;
  6822. },
  6823.  
  6824. _buildDescriptor: function()
  6825. {
  6826. var result = { type: "subMenu", label: this._label, enabled: !this._disabled, subItems: [] };
  6827. for (var i = 0; i < this._items.length; ++i)
  6828. result.subItems.push(this._items[i]._buildDescriptor());
  6829. return result;
  6830. },
  6831.  
  6832. __proto__: WebInspector.ContextMenuItem.prototype
  6833. }
  6834.  
  6835.  
  6836. WebInspector.ContextMenu = function(event) {
  6837. WebInspector.ContextSubMenuItem.call(this, this, "");
  6838. this._event = event;
  6839. this._handlers = {};
  6840. this._id = 0;
  6841. }
  6842.  
  6843. WebInspector.ContextMenu.prototype = {
  6844. nextId: function()
  6845. {
  6846. return this._id++;
  6847. },
  6848.  
  6849. show: function()
  6850. {
  6851. var menuObject = this._buildDescriptor();
  6852.  
  6853. if (menuObject.length) {
  6854. WebInspector._contextMenu = this;
  6855. InspectorFrontendHost.showContextMenu(this._event, menuObject);
  6856. }
  6857. this._event.consume();
  6858. },
  6859.  
  6860. showSoftMenu: function()
  6861. {
  6862. var menuObject = this._buildDescriptor();
  6863.  
  6864. if (menuObject.length) {
  6865. WebInspector._contextMenu = this;
  6866. var softMenu = new WebInspector.SoftContextMenu(menuObject);
  6867. softMenu.show(this._event, true);
  6868. }
  6869. this._event.consume();
  6870. },
  6871.  
  6872. _setHandler: function(id, handler)
  6873. {
  6874. if (handler)
  6875. this._handlers[id] = handler;
  6876. },
  6877.  
  6878. _buildDescriptor: function()
  6879. {
  6880. var result = [];
  6881. for (var i = 0; i < this._items.length; ++i)
  6882. result.push(this._items[i]._buildDescriptor());
  6883. return result;
  6884. },
  6885.  
  6886. _itemSelected: function(id)
  6887. {
  6888. if (this._handlers[id])
  6889. this._handlers[id].call(this);
  6890. },
  6891.  
  6892.  
  6893. appendApplicableItems: function(target)
  6894. {
  6895. for (var i = 0; i < WebInspector.ContextMenu._providers.length; ++i) {
  6896. var provider = WebInspector.ContextMenu._providers[i];
  6897. this.appendSeparator();
  6898. provider.appendApplicableItems(this._event, this, target);
  6899. this.appendSeparator();
  6900. }
  6901. },
  6902.  
  6903. __proto__: WebInspector.ContextSubMenuItem.prototype
  6904. }
  6905.  
  6906.  
  6907. WebInspector.ContextMenu.Provider = function() { 
  6908. }
  6909.  
  6910. WebInspector.ContextMenu.Provider.prototype = {
  6911.  
  6912. appendApplicableItems: function(event, contextMenu, target) { }
  6913. }
  6914.  
  6915.  
  6916. WebInspector.ContextMenu.registerProvider = function(provider)
  6917. {
  6918. WebInspector.ContextMenu._providers.push(provider);
  6919. }
  6920.  
  6921. WebInspector.ContextMenu._providers = [];
  6922.  
  6923. WebInspector.contextMenuItemSelected = function(id)
  6924. {
  6925. if (WebInspector._contextMenu)
  6926. WebInspector._contextMenu._itemSelected(id);
  6927. }
  6928.  
  6929. WebInspector.contextMenuCleared = function()
  6930. {
  6931.  
  6932.  
  6933. }
  6934.  
  6935.  
  6936.  
  6937.  
  6938.  
  6939.  
  6940. WebInspector.SoftContextMenu = function(items, parentMenu)
  6941. {
  6942. this._items = items;
  6943. this._parentMenu = parentMenu;
  6944. }
  6945.  
  6946. WebInspector.SoftContextMenu.prototype = {
  6947.  
  6948. show: function(event, alignToCurrentTarget)
  6949. {
  6950. this._x = event.x;
  6951. this._y = event.y;
  6952. this._time = new Date().getTime();
  6953.  
  6954.  
  6955. var absoluteX = event.pageX;
  6956. var absoluteY = event.pageY;
  6957. var targetElement = event.target;
  6958. while (targetElement && window !== targetElement.ownerDocument.defaultView) {
  6959. var frameElement = targetElement.ownerDocument.defaultView.frameElement;
  6960. absoluteY += frameElement.totalOffsetTop();
  6961. absoluteX += frameElement.totalOffsetLeft();
  6962. targetElement = frameElement;
  6963. }
  6964.  
  6965.  
  6966. var targetRect;
  6967. this._contextMenuElement = document.createElement("div");
  6968. this._contextMenuElement.className = "soft-context-menu";
  6969. this._contextMenuElement.tabIndex = 0;
  6970. if (alignToCurrentTarget) {
  6971. targetRect = event.currentTarget.getBoundingClientRect();
  6972.  
  6973. absoluteX = targetRect.left;
  6974. absoluteY = targetRect.bottom;
  6975. }
  6976. this._contextMenuElement.style.top = absoluteY + "px";
  6977. this._contextMenuElement.style.left = absoluteX + "px";
  6978.  
  6979. this._contextMenuElement.addEventListener("mouseup", consumeEvent, false);
  6980. this._contextMenuElement.addEventListener("keydown", this._menuKeyDown.bind(this), false);
  6981.  
  6982. for (var i = 0; i < this._items.length; ++i)
  6983. this._contextMenuElement.appendChild(this._createMenuItem(this._items[i]));
  6984.  
  6985.  
  6986. if (!this._parentMenu) {
  6987. this._glassPaneElement = document.createElement("div");
  6988. this._glassPaneElement.className = "soft-context-menu-glass-pane";
  6989. this._glassPaneElement.tabIndex = 0;
  6990. this._glassPaneElement.addEventListener("mouseup", this._glassPaneMouseUp.bind(this), false);
  6991. this._glassPaneElement.appendChild(this._contextMenuElement);
  6992. document.body.appendChild(this._glassPaneElement);
  6993. this._focus();
  6994. } else
  6995. this._parentMenu._parentGlassPaneElement().appendChild(this._contextMenuElement);
  6996.  
  6997.  
  6998. if (document.body.offsetWidth <  this._contextMenuElement.offsetLeft + this._contextMenuElement.offsetWidth) {
  6999. if (alignToCurrentTarget)
  7000. this._contextMenuElement.style.left = Math.max(0, targetRect.right - this._contextMenuElement.offsetWidth) + "px";
  7001. else
  7002. this._contextMenuElement.style.left = (absoluteX - this._contextMenuElement.offsetWidth) + "px";
  7003. }
  7004. if (document.body.offsetHeight < this._contextMenuElement.offsetTop + this._contextMenuElement.offsetHeight) {
  7005. if (alignToCurrentTarget)
  7006. this._contextMenuElement.style.top = Math.max(0, targetRect.top - this._contextMenuElement.offsetHeight) + "px";
  7007. else
  7008. this._contextMenuElement.style.top = (document.body.offsetHeight - this._contextMenuElement.offsetHeight) + "px";
  7009. }
  7010.  
  7011. event.consume(true);
  7012. },
  7013.  
  7014. _parentGlassPaneElement: function()
  7015. {
  7016. if (this._glassPaneElement)
  7017. return this._glassPaneElement;
  7018. if (this._parentMenu)
  7019. return this._parentMenu._parentGlassPaneElement();
  7020. return null;
  7021. },
  7022.  
  7023. _createMenuItem: function(item)
  7024. {
  7025. if (item.type === "separator")
  7026. return this._createSeparator();
  7027.  
  7028. if (item.type === "subMenu")
  7029. return this._createSubMenu(item);
  7030.  
  7031. var menuItemElement = document.createElement("div");
  7032. menuItemElement.className = "soft-context-menu-item";
  7033.  
  7034. var checkMarkElement = document.createElement("span");
  7035. checkMarkElement.textContent = "\u2713 "; 
  7036. checkMarkElement.className = "soft-context-menu-item-checkmark";
  7037. if (!item.checked)
  7038. checkMarkElement.style.opacity = "0";
  7039.  
  7040. menuItemElement.appendChild(checkMarkElement);
  7041. menuItemElement.appendChild(document.createTextNode(item.label));
  7042.  
  7043. menuItemElement.addEventListener("mousedown", this._menuItemMouseDown.bind(this), false);
  7044. menuItemElement.addEventListener("mouseup", this._menuItemMouseUp.bind(this), false);
  7045.  
  7046.  
  7047. menuItemElement.addEventListener("mouseover", this._menuItemMouseOver.bind(this), false);
  7048. menuItemElement.addEventListener("mouseout", this._menuItemMouseOut.bind(this), false);
  7049.  
  7050. menuItemElement._actionId = item.id;
  7051. return menuItemElement;
  7052. },
  7053.  
  7054. _createSubMenu: function(item)
  7055. {
  7056. var menuItemElement = document.createElement("div");
  7057. menuItemElement.className = "soft-context-menu-item";
  7058. menuItemElement._subItems = item.subItems;
  7059.  
  7060.  
  7061. var checkMarkElement = document.createElement("span");
  7062. checkMarkElement.textContent = "\u2713 "; 
  7063. checkMarkElement.className = "soft-context-menu-item-checkmark";
  7064. checkMarkElement.style.opacity = "0";
  7065. menuItemElement.appendChild(checkMarkElement);
  7066.  
  7067. var subMenuArrowElement = document.createElement("span");
  7068. subMenuArrowElement.textContent = "\u25B6"; 
  7069. subMenuArrowElement.className = "soft-context-menu-item-submenu-arrow";
  7070.  
  7071. menuItemElement.appendChild(document.createTextNode(item.label));
  7072. menuItemElement.appendChild(subMenuArrowElement);
  7073.  
  7074. menuItemElement.addEventListener("mousedown", this._menuItemMouseDown.bind(this), false);
  7075. menuItemElement.addEventListener("mouseup", this._menuItemMouseUp.bind(this), false);
  7076.  
  7077.  
  7078. menuItemElement.addEventListener("mouseover", this._menuItemMouseOver.bind(this), false);
  7079. menuItemElement.addEventListener("mouseout", this._menuItemMouseOut.bind(this), false);
  7080.  
  7081. return menuItemElement;
  7082. },
  7083.  
  7084. _createSeparator: function()
  7085. {
  7086. var separatorElement = document.createElement("div");
  7087. separatorElement.className = "soft-context-menu-separator";
  7088. separatorElement._isSeparator = true;
  7089. separatorElement.addEventListener("mouseover", this._hideSubMenu.bind(this), false);
  7090. separatorElement.createChild("div", "separator-line");
  7091. return separatorElement;
  7092. },
  7093.  
  7094. _menuItemMouseDown: function(event)
  7095. {
  7096.  
  7097. event.consume(true);
  7098. },
  7099.  
  7100. _menuItemMouseUp: function(event)
  7101. {
  7102. this._triggerAction(event.target, event);
  7103. event.consume();
  7104. },
  7105.  
  7106. _focus: function()
  7107. {
  7108. this._contextMenuElement.focus();
  7109. },
  7110.  
  7111. _triggerAction: function(menuItemElement, event)
  7112. {
  7113. if (!menuItemElement._subItems) {
  7114. this._discardMenu(true, event);
  7115. if (typeof menuItemElement._actionId !== "undefined") {
  7116. WebInspector.contextMenuItemSelected(menuItemElement._actionId);
  7117. delete menuItemElement._actionId;
  7118. }
  7119. return;
  7120. }
  7121.  
  7122. this._showSubMenu(menuItemElement, event);
  7123. event.consume();
  7124. },
  7125.  
  7126. _showSubMenu: function(menuItemElement, event)
  7127. {
  7128. if (menuItemElement._subMenuTimer) {
  7129. clearTimeout(menuItemElement._subMenuTimer);
  7130. delete menuItemElement._subMenuTimer;
  7131. }
  7132. if (this._subMenu)
  7133. return;
  7134.  
  7135. this._subMenu = new WebInspector.SoftContextMenu(menuItemElement._subItems, this);
  7136. this._subMenu.show(this._buildMouseEventForSubMenu(menuItemElement));
  7137. },
  7138.  
  7139. _buildMouseEventForSubMenu: function(subMenuItemElement)
  7140. {
  7141. var subMenuOffset = { x: subMenuItemElement.offsetWidth - 3, y: subMenuItemElement.offsetTop - 1 };
  7142. var targetX = this._x + subMenuOffset.x;
  7143. var targetY = this._y + subMenuOffset.y;
  7144. var targetPageX = parseInt(this._contextMenuElement.style.left, 10) + subMenuOffset.x;
  7145. var targetPageY = parseInt(this._contextMenuElement.style.top, 10) + subMenuOffset.y;
  7146. return { x: targetX, y: targetY, pageX: targetPageX, pageY: targetPageY, consume: function() {} };
  7147. },
  7148.  
  7149. _hideSubMenu: function()
  7150. {
  7151. if (!this._subMenu)
  7152. return;
  7153. this._subMenu._discardSubMenus();
  7154. this._focus();
  7155. },
  7156.  
  7157. _menuItemMouseOver: function(event)
  7158. {
  7159. this._highlightMenuItem(event.target);
  7160. },
  7161.  
  7162. _menuItemMouseOut: function(event)
  7163. {
  7164. if (!this._subMenu || !event.relatedTarget) {
  7165. this._highlightMenuItem(null);
  7166. return;
  7167. }
  7168.  
  7169. var relatedTarget = event.relatedTarget;
  7170. if (this._contextMenuElement.isSelfOrAncestor(relatedTarget) || relatedTarget.hasStyleClass("soft-context-menu-glass-pane"))
  7171. this._highlightMenuItem(null);
  7172. },
  7173.  
  7174. _highlightMenuItem: function(menuItemElement)
  7175. {
  7176. if (this._highlightedMenuItemElement ===  menuItemElement)
  7177. return;
  7178.  
  7179. this._hideSubMenu();
  7180. if (this._highlightedMenuItemElement) {
  7181. this._highlightedMenuItemElement.removeStyleClass("soft-context-menu-item-mouse-over");
  7182. if (this._highlightedMenuItemElement._subItems && this._highlightedMenuItemElement._subMenuTimer) {
  7183. clearTimeout(this._highlightedMenuItemElement._subMenuTimer);
  7184. delete this._highlightedMenuItemElement._subMenuTimer;
  7185. }
  7186. }
  7187. this._highlightedMenuItemElement = menuItemElement;
  7188. if (this._highlightedMenuItemElement) {
  7189. this._highlightedMenuItemElement.addStyleClass("soft-context-menu-item-mouse-over");
  7190. this._contextMenuElement.focus();
  7191. if (this._highlightedMenuItemElement._subItems && !this._highlightedMenuItemElement._subMenuTimer)
  7192. this._highlightedMenuItemElement._subMenuTimer = setTimeout(this._showSubMenu.bind(this, this._highlightedMenuItemElement, this._buildMouseEventForSubMenu(this._highlightedMenuItemElement)), 150);
  7193. }
  7194. },
  7195.  
  7196. _highlightPrevious: function()
  7197. {
  7198. var menuItemElement = this._highlightedMenuItemElement ? this._highlightedMenuItemElement.previousSibling : this._contextMenuElement.lastChild;
  7199. while (menuItemElement && menuItemElement._isSeparator)
  7200. menuItemElement = menuItemElement.previousSibling;
  7201. if (menuItemElement)
  7202. this._highlightMenuItem(menuItemElement);
  7203. },
  7204.  
  7205. _highlightNext: function()
  7206. {
  7207. var menuItemElement = this._highlightedMenuItemElement ? this._highlightedMenuItemElement.nextSibling : this._contextMenuElement.firstChild;
  7208. while (menuItemElement && menuItemElement._isSeparator)
  7209. menuItemElement = menuItemElement.nextSibling;
  7210. if (menuItemElement)
  7211. this._highlightMenuItem(menuItemElement);
  7212. },
  7213.  
  7214. _menuKeyDown: function(event)
  7215. {
  7216. switch (event.keyIdentifier) {
  7217. case "Up":
  7218. this._highlightPrevious(); break;
  7219. case "Down":
  7220. this._highlightNext(); break;
  7221. case "Left":
  7222. if (this._parentMenu) {
  7223. this._highlightMenuItem(null);
  7224. this._parentMenu._focus();
  7225. }
  7226. break;
  7227. case "Right":
  7228. if (!this._highlightedMenuItemElement)
  7229. break;
  7230. if (this._highlightedMenuItemElement._subItems) {
  7231. this._showSubMenu(this._highlightedMenuItemElement, this._buildMouseEventForSubMenu(this._highlightedMenuItemElement));
  7232. this._subMenu._focus();
  7233. this._subMenu._highlightNext();
  7234. }
  7235. break;
  7236. case "U+001B": 
  7237. this._discardMenu(true, event); break;
  7238. case "Enter":
  7239. if (!isEnterKey(event))
  7240. break;
  7241.  
  7242. case "U+0020": 
  7243. if (this._highlightedMenuItemElement)
  7244. this._triggerAction(this._highlightedMenuItemElement, event);
  7245. break;
  7246. }
  7247. event.consume(true);
  7248. },
  7249.  
  7250. _glassPaneMouseUp: function(event)
  7251. {
  7252.  
  7253. if (event.x === this._x && event.y === this._y && new Date().getTime() - this._time < 300)
  7254. return;
  7255. this._discardMenu(true, event);
  7256. event.consume();
  7257. },
  7258.  
  7259.  
  7260. _discardMenu: function(closeParentMenus, event)
  7261. {
  7262. if (this._subMenu && !closeParentMenus)
  7263. return;
  7264. if (this._glassPaneElement) {
  7265. var glassPane = this._glassPaneElement;
  7266. delete this._glassPaneElement;
  7267.  
  7268. document.body.removeChild(glassPane);
  7269. if (this._parentMenu) {
  7270. delete this._parentMenu._subMenu;
  7271. if (closeParentMenus)
  7272. this._parentMenu._discardMenu(closeParentMenus, event);
  7273. }
  7274.  
  7275. if (event)
  7276. event.consume(true);
  7277. } else if (this._parentMenu && this._contextMenuElement.parentElement) {
  7278. this._discardSubMenus();
  7279. if (closeParentMenus)
  7280. this._parentMenu._discardMenu(closeParentMenus, event);
  7281.  
  7282. if (event)
  7283. event.consume(true);
  7284. }
  7285. },
  7286.  
  7287. _discardSubMenus: function()
  7288. {
  7289. if (this._subMenu)
  7290. this._subMenu._discardSubMenus();
  7291. if (this._contextMenuElement.parentElement)
  7292. this._contextMenuElement.parentElement.removeChild(this._contextMenuElement);
  7293. if (this._parentMenu)
  7294. delete this._parentMenu._subMenu;
  7295. }
  7296. }
  7297.  
  7298. if (!InspectorFrontendHost.showContextMenu) {
  7299.  
  7300. InspectorFrontendHost.showContextMenu = function(event, items)
  7301. {
  7302. new WebInspector.SoftContextMenu(items).show(event);
  7303. }
  7304.  
  7305. }
  7306.  
  7307.  
  7308.  
  7309.  
  7310.  
  7311.  
  7312. WebInspector.KeyboardShortcut = function()
  7313. {
  7314. }
  7315.  
  7316.  
  7317. WebInspector.KeyboardShortcut.Modifiers = {
  7318. None: 0,   
  7319. Shift: 1,
  7320. Ctrl: 2,
  7321. Alt: 4,
  7322. Meta: 8,   
  7323. get CtrlOrMeta()
  7324. {
  7325.  
  7326. return WebInspector.isMac() ? this.Meta : this.Ctrl;
  7327. }
  7328. };
  7329.  
  7330.  
  7331. WebInspector.KeyboardShortcut.Key;
  7332.  
  7333.  
  7334. WebInspector.KeyboardShortcut.Keys = {
  7335. Backspace: { code: 8, name: "\u21a4" },
  7336. Tab: { code: 9, name: { mac: "\u21e5", other: "<Tab>" } },
  7337. Enter: { code: 13, name: { mac: "\u21a9", other: "<Enter>" } },
  7338. Esc: { code: 27, name: { mac: "\u238b", other: "<Esc>" } },
  7339. Space: { code: 32, name: "<Space>" },
  7340. PageUp: { code: 33,  name: { mac: "\u21de", other: "<PageUp>" } },      
  7341. PageDown: { code: 34, name: { mac: "\u21df", other: "<PageDown>" } },   
  7342. End: { code: 35, name: { mac: "\u2197", other: "<End>" } },             
  7343. Home: { code: 36, name: { mac: "\u2196", other: "<Home>" } },           
  7344. Left: { code: 37, name: "<Left>" },           
  7345. Up: { code: 38, name: "<Up>" },             
  7346. Right: { code: 39, name: "<Right>" },          
  7347. Down: { code: 40, name: "<Down>" },           
  7348. Delete: { code: 46, name: "<Del>" },
  7349. Zero: { code: 48, name: "0" },
  7350. F1: { code: 112, name: "F1" },
  7351. F2: { code: 113, name: "F2" },
  7352. F3: { code: 114, name: "F3" },
  7353. F4: { code: 115, name: "F4" },
  7354. F5: { code: 116, name: "F5" },
  7355. F6: { code: 117, name: "F6" },
  7356. F7: { code: 118, name: "F7" },
  7357. F8: { code: 119, name: "F8" },
  7358. F9: { code: 120, name: "F9" },
  7359. F10: { code: 121, name: "F10" },
  7360. F11: { code: 122, name: "F11" },
  7361. F12: { code: 123, name: "F12" },
  7362. Semicolon: { code: 186, name: ";" },
  7363. Plus: { code: 187, name: "+" },
  7364. Comma: { code: 188, name: "," },
  7365. Minus: { code: 189, name: "-" },
  7366. Period: { code: 190, name: "." },
  7367. Slash: { code: 191, name: "/" },
  7368. Apostrophe: { code: 192, name: "`" },
  7369. SingleQuote: { code: 222, name: "\'" },
  7370. H: { code: 72, name: "H" }
  7371. };
  7372.  
  7373.  
  7374. WebInspector.KeyboardShortcut.makeKey = function(keyCode, modifiers)
  7375. {
  7376. if (typeof keyCode === "string")
  7377. keyCode = keyCode.charCodeAt(0) - 32;
  7378. modifiers = modifiers || WebInspector.KeyboardShortcut.Modifiers.None;
  7379. return WebInspector.KeyboardShortcut._makeKeyFromCodeAndModifiers(keyCode, modifiers);
  7380. }
  7381.  
  7382.  
  7383. WebInspector.KeyboardShortcut.makeKeyFromEvent = function(keyboardEvent)
  7384. {
  7385. var modifiers = WebInspector.KeyboardShortcut.Modifiers.None;
  7386. if (keyboardEvent.shiftKey)
  7387. modifiers |= WebInspector.KeyboardShortcut.Modifiers.Shift;
  7388. if (keyboardEvent.ctrlKey)
  7389. modifiers |= WebInspector.KeyboardShortcut.Modifiers.Ctrl;
  7390. if (keyboardEvent.altKey)
  7391. modifiers |= WebInspector.KeyboardShortcut.Modifiers.Alt;
  7392. if (keyboardEvent.metaKey)
  7393. modifiers |= WebInspector.KeyboardShortcut.Modifiers.Meta;
  7394. return WebInspector.KeyboardShortcut._makeKeyFromCodeAndModifiers(keyboardEvent.keyCode, modifiers);
  7395. }
  7396.  
  7397.  
  7398. WebInspector.KeyboardShortcut.eventHasCtrlOrMeta = function(event)
  7399. {
  7400. return WebInspector.isMac() ? event.metaKey && !event.ctrlKey : event.ctrlKey && !event.metaKey;
  7401. }
  7402.  
  7403.  
  7404. WebInspector.KeyboardShortcut.hasNoModifiers = function(event)
  7405. {
  7406. return !event.ctrlKey && !event.shiftKey && !event.altKey && !event.metaKey;
  7407. }
  7408.  
  7409.  
  7410. WebInspector.KeyboardShortcut.Descriptor;
  7411.  
  7412.  
  7413. WebInspector.KeyboardShortcut.makeDescriptor = function(key, modifiers)
  7414. {
  7415. return {
  7416. key: WebInspector.KeyboardShortcut.makeKey(typeof key === "string" ? key : key.code, modifiers),
  7417. name: WebInspector.KeyboardShortcut.shortcutToString(key, modifiers)
  7418. };
  7419. }
  7420.  
  7421.  
  7422. WebInspector.KeyboardShortcut.shortcutToString = function(key, modifiers)
  7423. {
  7424. return WebInspector.KeyboardShortcut._modifiersToString(modifiers) + WebInspector.KeyboardShortcut._keyName(key);
  7425. }
  7426.  
  7427.  
  7428. WebInspector.KeyboardShortcut._keyName = function(key)
  7429. {
  7430. if (typeof key === "string")
  7431. return key.toUpperCase();
  7432. if (typeof key.name === "string")
  7433. return key.name;
  7434. return key.name[WebInspector.platform()] || key.name.other || '';
  7435. }
  7436.  
  7437.  
  7438. WebInspector.KeyboardShortcut._makeKeyFromCodeAndModifiers = function(keyCode, modifiers)
  7439. {
  7440. return (keyCode & 255) | (modifiers << 8);
  7441. };
  7442.  
  7443.  
  7444. WebInspector.KeyboardShortcut._modifiersToString = function(modifiers)
  7445. {
  7446. const cmdKey = "\u2318";
  7447. const optKey = "\u2325";
  7448. const shiftKey = "\u21e7";
  7449. const ctrlKey = "\u2303";
  7450.  
  7451. var isMac = WebInspector.isMac();
  7452. var res = "";
  7453. if (modifiers & WebInspector.KeyboardShortcut.Modifiers.Ctrl)
  7454. res += isMac ? ctrlKey : "<Ctrl> + ";
  7455. if (modifiers & WebInspector.KeyboardShortcut.Modifiers.Alt)
  7456. res += isMac ? optKey : "<Alt> + ";
  7457. if (modifiers & WebInspector.KeyboardShortcut.Modifiers.Shift)
  7458. res += isMac ? shiftKey : "<Shift> + ";
  7459. if (modifiers & WebInspector.KeyboardShortcut.Modifiers.Meta)
  7460. res += isMac ? cmdKey : "<Win> + ";
  7461.  
  7462. return res;
  7463. };
  7464.  
  7465. WebInspector.KeyboardShortcut.SelectAll = WebInspector.KeyboardShortcut.makeKey("a", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta);
  7466.  
  7467.  
  7468.  
  7469.  
  7470.  
  7471.  
  7472. WebInspector.TextPrompt = function(completions, stopCharacters)
  7473. {
  7474.  
  7475. this._proxyElement;
  7476. this._proxyElementDisplay = "inline-block";
  7477. this._loadCompletions = completions;
  7478. this._completionStopCharacters = stopCharacters || " =:[({;,!+-*/&|^<>.";
  7479. this._suggestForceable = true;
  7480. }
  7481.  
  7482. WebInspector.TextPrompt.Events = {
  7483. ItemApplied: "text-prompt-item-applied",
  7484. ItemAccepted: "text-prompt-item-accepted"
  7485. };
  7486.  
  7487. WebInspector.TextPrompt.prototype = {
  7488. get proxyElement()
  7489. {
  7490. return this._proxyElement;
  7491. },
  7492.  
  7493. setSuggestForceable: function(x)
  7494. {
  7495. this._suggestForceable = x;
  7496. },
  7497.  
  7498. setSuggestBoxEnabled: function(className)
  7499. {
  7500. this._suggestBoxClassName = className;
  7501. },
  7502.  
  7503. renderAsBlock: function()
  7504. {
  7505. this._proxyElementDisplay = "block";
  7506. },
  7507.  
  7508.  
  7509. attach: function(element)
  7510. {
  7511. return this._attachInternal(element);
  7512. },
  7513.  
  7514.  
  7515. attachAndStartEditing: function(element, blurListener)
  7516. {
  7517. this._attachInternal(element);
  7518. this._startEditing(blurListener);
  7519. return this.proxyElement;
  7520. },
  7521.  
  7522. _attachInternal: function(element)
  7523. {
  7524. if (this.proxyElement)
  7525. throw "Cannot attach an attached TextPrompt";
  7526. this._element = element;
  7527.  
  7528. this._boundOnKeyDown = this.onKeyDown.bind(this);
  7529. this._boundOnMouseWheel = this.onMouseWheel.bind(this);
  7530. this._boundSelectStart = this._selectStart.bind(this);
  7531. this._proxyElement = element.ownerDocument.createElement("span");
  7532. this._proxyElement.style.display = this._proxyElementDisplay;
  7533. element.parentElement.insertBefore(this.proxyElement, element);
  7534. this.proxyElement.appendChild(element);
  7535. this._element.addStyleClass("text-prompt");
  7536. this._element.addEventListener("keydown", this._boundOnKeyDown, false);
  7537. this._element.addEventListener("mousewheel", this._boundOnMouseWheel, false);
  7538. this._element.addEventListener("selectstart", this._boundSelectStart, false);
  7539.  
  7540. if (typeof this._suggestBoxClassName === "string")
  7541. this._suggestBox = new WebInspector.TextPrompt.SuggestBox(this, this._element, this._suggestBoxClassName);
  7542.  
  7543. return this.proxyElement;
  7544. },
  7545.  
  7546. detach: function()
  7547. {
  7548. this._removeFromElement();
  7549. this.proxyElement.parentElement.insertBefore(this._element, this.proxyElement);
  7550. this.proxyElement.parentElement.removeChild(this.proxyElement);
  7551. this._element.removeStyleClass("text-prompt");
  7552. this._element.removeEventListener("keydown", this._boundOnKeyDown, false);
  7553. this._element.removeEventListener("mousewheel", this._boundOnMouseWheel, false);
  7554. this._element.removeEventListener("selectstart", this._boundSelectStart, false);
  7555. delete this._proxyElement;
  7556. WebInspector.restoreFocusFromElement(this._element);
  7557. },
  7558.  
  7559. get text()
  7560. {
  7561. return this._element.textContent;
  7562. },
  7563.  
  7564. set text(x)
  7565. {
  7566. this._removeSuggestionAids();
  7567. if (!x) {
  7568.  
  7569. this._element.removeChildren();
  7570. this._element.appendChild(document.createElement("br"));
  7571. } else
  7572. this._element.textContent = x;
  7573.  
  7574. this.moveCaretToEndOfPrompt();
  7575. this._element.scrollIntoView();
  7576. },
  7577.  
  7578. _removeFromElement: function()
  7579. {
  7580. this.clearAutoComplete(true);
  7581. this._element.removeEventListener("keydown", this._boundOnKeyDown, false);
  7582. this._element.removeEventListener("selectstart", this._boundSelectStart, false);
  7583. if (this._isEditing)
  7584. this._stopEditing();
  7585. if (this._suggestBox)
  7586. this._suggestBox.removeFromElement();
  7587. },
  7588.  
  7589. _startEditing: function(blurListener)
  7590. {
  7591. this._isEditing = true;
  7592. this._element.addStyleClass("editing");
  7593. if (blurListener) {
  7594. this._blurListener = blurListener;
  7595. this._element.addEventListener("blur", this._blurListener, false);
  7596. }
  7597. this._oldTabIndex = this._element.tabIndex;
  7598. if (this._element.tabIndex < 0)
  7599. this._element.tabIndex = 0;
  7600. WebInspector.setCurrentFocusElement(this._element);
  7601. },
  7602.  
  7603. _stopEditing: function()
  7604. {
  7605. this._element.tabIndex = this._oldTabIndex;
  7606. if (this._blurListener)
  7607. this._element.removeEventListener("blur", this._blurListener, false);
  7608. this._element.removeStyleClass("editing");
  7609. delete this._isEditing;
  7610. },
  7611.  
  7612. _removeSuggestionAids: function()
  7613. {
  7614. this.clearAutoComplete();
  7615. this.hideSuggestBox();
  7616. },
  7617.  
  7618. _selectStart: function(event)
  7619. {
  7620. if (this._selectionTimeout)
  7621. clearTimeout(this._selectionTimeout);
  7622.  
  7623. this._removeSuggestionAids();
  7624.  
  7625. function moveBackIfOutside()
  7626. {
  7627. delete this._selectionTimeout;
  7628. if (!this.isCaretInsidePrompt() && window.getSelection().isCollapsed) {
  7629. this.moveCaretToEndOfPrompt();
  7630. this.autoCompleteSoon();
  7631. }
  7632. }
  7633.  
  7634. this._selectionTimeout = setTimeout(moveBackIfOutside.bind(this), 100);
  7635. },
  7636.  
  7637.  
  7638. defaultKeyHandler: function(event, force)
  7639. {
  7640. this.clearAutoComplete();
  7641. this.autoCompleteSoon(force);
  7642. return false;
  7643. },
  7644.  
  7645. onMouseWheel: function(event)
  7646. {
  7647.  
  7648. },
  7649.  
  7650. onKeyDown: function(event)
  7651. {
  7652. var handled = false;
  7653. var invokeDefault = true;
  7654.  
  7655. switch (event.keyIdentifier) {
  7656. case "Up":
  7657. handled = this.upKeyPressed(event);
  7658. break;
  7659. case "Down":
  7660. handled = this.downKeyPressed(event);
  7661. break;
  7662. case "PageUp":
  7663. handled = this.pageUpKeyPressed(event);
  7664. break;
  7665. case "PageDown":
  7666. handled = this.pageDownKeyPressed(event);
  7667. break;
  7668. case "U+0009": 
  7669. handled = this.tabKeyPressed(event);
  7670. break;
  7671. case "Enter":
  7672. handled = this.enterKeyPressed(event);
  7673. break;
  7674. case "Left":
  7675. case "Home":
  7676. this._removeSuggestionAids();
  7677. invokeDefault = false;
  7678. break;
  7679. case "Right":
  7680. case "End":
  7681. if (this.isCaretAtEndOfPrompt())
  7682. handled = this.acceptAutoComplete();
  7683. else
  7684. this._removeSuggestionAids();
  7685. invokeDefault = false;
  7686. break;
  7687. case "U+001B": 
  7688. if (this.isSuggestBoxVisible()) {
  7689. this._suggestBox.hide();
  7690. handled = true;
  7691. }
  7692. break;
  7693. case "U+0020": 
  7694. if (this._suggestForceable && event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
  7695. this.defaultKeyHandler(event, true);
  7696. handled = true;
  7697. }
  7698. break;
  7699. case "Alt":
  7700. case "Meta":
  7701. case "Shift":
  7702. case "Control":
  7703. invokeDefault = false;
  7704. break;
  7705. }
  7706.  
  7707. if (!handled && invokeDefault)
  7708. handled = this.defaultKeyHandler(event);
  7709.  
  7710. if (handled)
  7711. event.consume(true);
  7712.  
  7713. return handled;
  7714. },
  7715.  
  7716. acceptAutoComplete: function()
  7717. {
  7718. var result = false;
  7719. if (this.isSuggestBoxVisible())
  7720. result = this._suggestBox.acceptSuggestion();
  7721. if (!result)
  7722. result = this.acceptSuggestion();
  7723.  
  7724. return result;
  7725. },
  7726.  
  7727.  
  7728. clearAutoComplete: function(includeTimeout)
  7729. {
  7730. if (includeTimeout && this._completeTimeout) {
  7731. clearTimeout(this._completeTimeout);
  7732. delete this._completeTimeout;
  7733. }
  7734. delete this._waitingForCompletions;
  7735.  
  7736. if (!this.autoCompleteElement)
  7737. return;
  7738.  
  7739. if (this.autoCompleteElement.parentNode)
  7740. this.autoCompleteElement.parentNode.removeChild(this.autoCompleteElement);
  7741. delete this.autoCompleteElement;
  7742.  
  7743. if (!this._userEnteredRange || !this._userEnteredText)
  7744. return;
  7745.  
  7746. this._userEnteredRange.deleteContents();
  7747. this._element.normalize();
  7748.  
  7749. var userTextNode = document.createTextNode(this._userEnteredText);
  7750. this._userEnteredRange.insertNode(userTextNode);
  7751.  
  7752. var selectionRange = document.createRange();
  7753. selectionRange.setStart(userTextNode, this._userEnteredText.length);
  7754. selectionRange.setEnd(userTextNode, this._userEnteredText.length);
  7755.  
  7756. var selection = window.getSelection();
  7757. selection.removeAllRanges();
  7758. selection.addRange(selectionRange);
  7759.  
  7760. delete this._userEnteredRange;
  7761. delete this._userEnteredText;
  7762. },
  7763.  
  7764.  
  7765. autoCompleteSoon: function(force)
  7766. {
  7767. var immediately = this.isSuggestBoxVisible() || force;
  7768. if (!this._completeTimeout)
  7769. this._completeTimeout = setTimeout(this.complete.bind(this, true, force), immediately ? 0 : 250);
  7770. },
  7771.  
  7772.  
  7773. complete: function(auto, force, reverse)
  7774. {
  7775. this.clearAutoComplete(true);
  7776. var selection = window.getSelection();
  7777. if (!selection.rangeCount)
  7778. return;
  7779.  
  7780. var selectionRange = selection.getRangeAt(0);
  7781. var isEmptyInput = selectionRange.commonAncestorContainer === this._element; 
  7782.  
  7783. var shouldExit;
  7784.  
  7785.  
  7786. if (auto && isEmptyInput && !force)
  7787. shouldExit = true;
  7788. else if (!auto && !isEmptyInput && !selectionRange.commonAncestorContainer.isDescendant(this._element))
  7789. shouldExit = true;
  7790. else if (auto && !force && !this.isCaretAtEndOfPrompt() && !this.isSuggestBoxVisible())
  7791. shouldExit = true;
  7792. else if (!selection.isCollapsed)
  7793. shouldExit = true;
  7794. else if (!force) {
  7795.  
  7796. var wordSuffixRange = selectionRange.startContainer.rangeOfWord(selectionRange.endOffset, this._completionStopCharacters, this._element, "forward");
  7797. if (wordSuffixRange.toString().length)
  7798. shouldExit = true;
  7799. }
  7800. if (shouldExit) {
  7801. this.hideSuggestBox();
  7802. return;
  7803. }
  7804.  
  7805. var wordPrefixRange = selectionRange.startContainer.rangeOfWord(selectionRange.startOffset, this._completionStopCharacters, this._element, "backward");
  7806. this._waitingForCompletions = true;
  7807. this._loadCompletions(this.proxyElement, wordPrefixRange, force, this._completionsReady.bind(this, selection, auto, wordPrefixRange, !!reverse));
  7808. },
  7809.  
  7810. _boxForAnchorAtStart: function(selection, textRange)
  7811. {
  7812. var rangeCopy = selection.getRangeAt(0).cloneRange();
  7813. var anchorElement = document.createElement("span");
  7814. anchorElement.textContent = "\u200B";
  7815. textRange.insertNode(anchorElement);
  7816. var box = anchorElement.boxInWindow(window);
  7817. anchorElement.parentElement.removeChild(anchorElement);
  7818. selection.removeAllRanges();
  7819. selection.addRange(rangeCopy);
  7820. return box;
  7821. },
  7822.  
  7823.  
  7824. _buildCommonPrefix: function(completions, wordPrefixLength)
  7825. {
  7826. var commonPrefix = completions[0];
  7827. for (var i = 0; i < completions.length; ++i) {
  7828. var completion = completions[i];
  7829. var lastIndex = Math.min(commonPrefix.length, completion.length);
  7830. for (var j = wordPrefixLength; j < lastIndex; ++j) {
  7831. if (commonPrefix[j] !== completion[j]) {
  7832. commonPrefix = commonPrefix.substr(0, j);
  7833. break;
  7834. }
  7835. }
  7836. }
  7837. return commonPrefix;
  7838. },
  7839.  
  7840.  
  7841. _completionsReady: function(selection, auto, originalWordPrefixRange, reverse, completions, selectedIndex)
  7842. {
  7843. if (!this._waitingForCompletions || !completions || !completions.length) {
  7844. this.hideSuggestBox();
  7845. return;
  7846. }
  7847. delete this._waitingForCompletions;
  7848.  
  7849. var selectionRange = selection.getRangeAt(0);
  7850.  
  7851. var fullWordRange = document.createRange();
  7852. fullWordRange.setStart(originalWordPrefixRange.startContainer, originalWordPrefixRange.startOffset);
  7853. fullWordRange.setEnd(selectionRange.endContainer, selectionRange.endOffset);
  7854.  
  7855. if (originalWordPrefixRange.toString() + selectionRange.toString() != fullWordRange.toString())
  7856. return;
  7857.  
  7858. selectedIndex = selectedIndex || 0;
  7859.  
  7860. this._userEnteredRange = fullWordRange;
  7861. this._userEnteredText = fullWordRange.toString();
  7862.  
  7863. if (this._suggestBox)
  7864. this._suggestBox.updateSuggestions(this._boxForAnchorAtStart(selection, fullWordRange), completions, selectedIndex, !this.isCaretAtEndOfPrompt());
  7865.  
  7866. var wordPrefixLength = originalWordPrefixRange.toString().length;
  7867.  
  7868. if (auto) {
  7869. var completionText = completions[selectedIndex];
  7870. var commonPrefix = this._buildCommonPrefix(completions, wordPrefixLength);
  7871.  
  7872. this._commonPrefix = commonPrefix;
  7873. } else {
  7874. if (completions.length === 1) {
  7875. var completionText = completions[selectedIndex];
  7876. wordPrefixLength = completionText.length;
  7877. } else {
  7878. var commonPrefix = this._buildCommonPrefix(completions, wordPrefixLength);
  7879. wordPrefixLength = commonPrefix.length;
  7880.  
  7881. if (selection.isCollapsed)
  7882. var completionText = completions[selectedIndex];
  7883. else {
  7884. var currentText = fullWordRange.toString();
  7885.  
  7886. var foundIndex = null;
  7887. for (var i = 0; i < completions.length; ++i) {
  7888. if (completions[i] === currentText)
  7889. foundIndex = i;
  7890. }
  7891.  
  7892. var nextIndex = foundIndex + (reverse ? -1 : 1);
  7893. if (foundIndex === null || nextIndex >= completions.length)
  7894. var completionText = completions[selectedIndex];
  7895. else if (nextIndex < 0)
  7896. var completionText = completions[completions.length - 1];
  7897. else
  7898. var completionText = completions[nextIndex];
  7899. }
  7900. }
  7901. }
  7902.  
  7903. if (auto) {
  7904. if (this.isCaretAtEndOfPrompt()) {
  7905. this._userEnteredRange.deleteContents();
  7906. this._element.normalize();
  7907. var finalSelectionRange = document.createRange();
  7908. var prefixText = completionText.substring(0, wordPrefixLength);
  7909. var suffixText = completionText.substring(wordPrefixLength);
  7910.  
  7911. var prefixTextNode = document.createTextNode(prefixText);
  7912. fullWordRange.insertNode(prefixTextNode);
  7913.  
  7914. this.autoCompleteElement = document.createElement("span");
  7915. this.autoCompleteElement.className = "auto-complete-text";
  7916. this.autoCompleteElement.textContent = suffixText;
  7917.  
  7918. prefixTextNode.parentNode.insertBefore(this.autoCompleteElement, prefixTextNode.nextSibling);
  7919.  
  7920. finalSelectionRange.setStart(prefixTextNode, wordPrefixLength);
  7921. finalSelectionRange.setEnd(prefixTextNode, wordPrefixLength);
  7922. selection.removeAllRanges();
  7923. selection.addRange(finalSelectionRange);
  7924. }
  7925. } else
  7926. this.applySuggestion(completionText, completions.length > 1, originalWordPrefixRange);
  7927. },
  7928.  
  7929. _completeCommonPrefix: function()
  7930. {
  7931. if (!this.autoCompleteElement || !this._commonPrefix || !this._userEnteredText || !this._commonPrefix.startsWith(this._userEnteredText))
  7932. return;
  7933.  
  7934. if (!this.isSuggestBoxVisible()) {
  7935. this.acceptAutoComplete();
  7936. return;
  7937. }
  7938.  
  7939. this.autoCompleteElement.textContent = this._commonPrefix.substring(this._userEnteredText.length);
  7940. this.acceptSuggestion(true)
  7941. },
  7942.  
  7943.  
  7944. applySuggestion: function(completionText, isIntermediateSuggestion, originalPrefixRange)
  7945. {
  7946. var wordPrefixLength;
  7947. if (originalPrefixRange)
  7948. wordPrefixLength = originalPrefixRange.toString().length;
  7949. else
  7950. wordPrefixLength = this._userEnteredText ? this._userEnteredText.length : 0;
  7951.  
  7952. this._userEnteredRange.deleteContents();
  7953. this._element.normalize();
  7954. var finalSelectionRange = document.createRange();
  7955. var completionTextNode = document.createTextNode(completionText);
  7956. this._userEnteredRange.insertNode(completionTextNode);
  7957. if (this.autoCompleteElement && this.autoCompleteElement.parentNode) {
  7958. this.autoCompleteElement.parentNode.removeChild(this.autoCompleteElement);
  7959. delete this.autoCompleteElement;
  7960. }
  7961.  
  7962. if (isIntermediateSuggestion)
  7963. finalSelectionRange.setStart(completionTextNode, wordPrefixLength);
  7964. else
  7965. finalSelectionRange.setStart(completionTextNode, completionText.length);
  7966.  
  7967. finalSelectionRange.setEnd(completionTextNode, completionText.length);
  7968.  
  7969. var selection = window.getSelection();
  7970. selection.removeAllRanges();
  7971. selection.addRange(finalSelectionRange);
  7972. if (isIntermediateSuggestion)
  7973. this.dispatchEventToListeners(WebInspector.TextPrompt.Events.ItemApplied, { itemText: completionText });
  7974. },
  7975.  
  7976.  
  7977. acceptSuggestion: function(prefixAccepted)
  7978. {
  7979. if (this._isAcceptingSuggestion)
  7980. return false;
  7981.  
  7982. if (!this.autoCompleteElement || !this.autoCompleteElement.parentNode)
  7983. return false;
  7984.  
  7985. var text = this.autoCompleteElement.textContent;
  7986. var textNode = document.createTextNode(text);
  7987. this.autoCompleteElement.parentNode.replaceChild(textNode, this.autoCompleteElement);
  7988. delete this.autoCompleteElement;
  7989.  
  7990. var finalSelectionRange = document.createRange();
  7991. finalSelectionRange.setStart(textNode, text.length);
  7992. finalSelectionRange.setEnd(textNode, text.length);
  7993.  
  7994. var selection = window.getSelection();
  7995. selection.removeAllRanges();
  7996. selection.addRange(finalSelectionRange);
  7997.  
  7998. if (!prefixAccepted) {
  7999. this.hideSuggestBox();
  8000. this.dispatchEventToListeners(WebInspector.TextPrompt.Events.ItemAccepted);
  8001. } else
  8002. this.autoCompleteSoon(true);
  8003.  
  8004. return true;
  8005. },
  8006.  
  8007. hideSuggestBox: function()
  8008. {
  8009. if (this.isSuggestBoxVisible())
  8010. this._suggestBox.hide();
  8011. },
  8012.  
  8013. isSuggestBoxVisible: function()
  8014. {
  8015. return this._suggestBox && this._suggestBox.visible;
  8016. },
  8017.  
  8018. isCaretInsidePrompt: function()
  8019. {
  8020. return this._element.isInsertionCaretInside();
  8021. },
  8022.  
  8023. isCaretAtEndOfPrompt: function()
  8024. {
  8025. var selection = window.getSelection();
  8026. if (!selection.rangeCount || !selection.isCollapsed)
  8027. return false;
  8028.  
  8029. var selectionRange = selection.getRangeAt(0);
  8030. var node = selectionRange.startContainer;
  8031. if (!node.isSelfOrDescendant(this._element))
  8032. return false;
  8033.  
  8034. if (node.nodeType === Node.TEXT_NODE && selectionRange.startOffset < node.nodeValue.length)
  8035. return false;
  8036.  
  8037. var foundNextText = false;
  8038. while (node) {
  8039. if (node.nodeType === Node.TEXT_NODE && node.nodeValue.length) {
  8040. if (foundNextText && (!this.autoCompleteElement || !this.autoCompleteElement.isAncestor(node)))
  8041. return false;
  8042. foundNextText = true;
  8043. }
  8044.  
  8045. node = node.traverseNextNode(this._element);
  8046. }
  8047.  
  8048. return true;
  8049. },
  8050.  
  8051. isCaretOnFirstLine: function()
  8052. {
  8053. var selection = window.getSelection();
  8054. var focusNode = selection.focusNode;
  8055. if (!focusNode || focusNode.nodeType !== Node.TEXT_NODE || focusNode.parentNode !== this._element)
  8056. return true;
  8057.  
  8058. if (focusNode.textContent.substring(0, selection.focusOffset).indexOf("\n") !== -1)
  8059. return false;
  8060. focusNode = focusNode.previousSibling;
  8061.  
  8062. while (focusNode) {
  8063. if (focusNode.nodeType !== Node.TEXT_NODE)
  8064. return true;
  8065. if (focusNode.textContent.indexOf("\n") !== -1)
  8066. return false;
  8067. focusNode = focusNode.previousSibling;
  8068. }
  8069.  
  8070. return true;
  8071. },
  8072.  
  8073. isCaretOnLastLine: function()
  8074. {
  8075. var selection = window.getSelection();
  8076. var focusNode = selection.focusNode;
  8077. if (!focusNode || focusNode.nodeType !== Node.TEXT_NODE || focusNode.parentNode !== this._element)
  8078. return true;
  8079.  
  8080. if (focusNode.textContent.substring(selection.focusOffset).indexOf("\n") !== -1)
  8081. return false;
  8082. focusNode = focusNode.nextSibling;
  8083.  
  8084. while (focusNode) {
  8085. if (focusNode.nodeType !== Node.TEXT_NODE)
  8086. return true;
  8087. if (focusNode.textContent.indexOf("\n") !== -1)
  8088. return false;
  8089. focusNode = focusNode.nextSibling;
  8090. }
  8091.  
  8092. return true;
  8093. },
  8094.  
  8095. moveCaretToEndOfPrompt: function()
  8096. {
  8097. var selection = window.getSelection();
  8098. var selectionRange = document.createRange();
  8099.  
  8100. var offset = this._element.childNodes.length;
  8101. selectionRange.setStart(this._element, offset);
  8102. selectionRange.setEnd(this._element, offset);
  8103.  
  8104. selection.removeAllRanges();
  8105. selection.addRange(selectionRange);
  8106. },
  8107.  
  8108. tabKeyPressed: function(event)
  8109. {
  8110. this._completeCommonPrefix();
  8111.  
  8112.  
  8113. return true;
  8114. },
  8115.  
  8116. enterKeyPressed: function(event)
  8117. {
  8118. if (this.isSuggestBoxVisible())
  8119. return this._suggestBox.enterKeyPressed(event);
  8120.  
  8121. return false;
  8122. },
  8123.  
  8124. upKeyPressed: function(event)
  8125. {
  8126. if (this.isSuggestBoxVisible())
  8127. return this._suggestBox.upKeyPressed(event);
  8128.  
  8129. return false;
  8130. },
  8131.  
  8132. downKeyPressed: function(event)
  8133. {
  8134. if (this.isSuggestBoxVisible())
  8135. return this._suggestBox.downKeyPressed(event);
  8136.  
  8137. return false;
  8138. },
  8139.  
  8140. pageUpKeyPressed: function(event)
  8141. {
  8142. if (this.isSuggestBoxVisible())
  8143. return this._suggestBox.pageUpKeyPressed(event);
  8144.  
  8145. return false;
  8146. },
  8147.  
  8148. pageDownKeyPressed: function(event)
  8149. {
  8150. if (this.isSuggestBoxVisible())
  8151. return this._suggestBox.pageDownKeyPressed(event);
  8152.  
  8153. return false;
  8154. },
  8155.  
  8156. __proto__: WebInspector.Object.prototype
  8157. }
  8158.  
  8159.  
  8160.  
  8161. WebInspector.TextPromptWithHistory = function(completions, stopCharacters)
  8162. {
  8163. WebInspector.TextPrompt.call(this, completions, stopCharacters);
  8164.  
  8165.  
  8166. this._data = [];
  8167.  
  8168.  
  8169. this._historyOffset = 1;
  8170.  
  8171.  
  8172. this._coalesceHistoryDupes = true;
  8173. }
  8174.  
  8175. WebInspector.TextPromptWithHistory.prototype = {
  8176. get historyData()
  8177. {
  8178.  
  8179. return this._data;
  8180. },
  8181.  
  8182. setCoalesceHistoryDupes: function(x)
  8183. {
  8184. this._coalesceHistoryDupes = x;
  8185. },
  8186.  
  8187.  
  8188. setHistoryData: function(data)
  8189. {
  8190. this._data = [].concat(data);
  8191. this._historyOffset = 1;
  8192. },
  8193.  
  8194.  
  8195. pushHistoryItem: function(text)
  8196. {
  8197. if (this._uncommittedIsTop) {
  8198. this._data.pop();
  8199. delete this._uncommittedIsTop;
  8200. }
  8201.  
  8202. this._historyOffset = 1;
  8203. if (this._coalesceHistoryDupes && text === this._currentHistoryItem())
  8204. return;
  8205. this._data.push(text);
  8206. },
  8207.  
  8208.  
  8209. _pushCurrentText: function()
  8210. {
  8211. if (this._uncommittedIsTop)
  8212. this._data.pop(); 
  8213. this._uncommittedIsTop = true;
  8214. this.clearAutoComplete(true);
  8215. this._data.push(this.text);
  8216. },
  8217.  
  8218.  
  8219. _previous: function()
  8220. {
  8221. if (this._historyOffset > this._data.length)
  8222. return undefined;
  8223. if (this._historyOffset === 1)
  8224. this._pushCurrentText();
  8225. ++this._historyOffset;
  8226. return this._currentHistoryItem();
  8227. },
  8228.  
  8229.  
  8230. _next: function()
  8231. {
  8232. if (this._historyOffset === 1)
  8233. return undefined;
  8234. --this._historyOffset;
  8235. return this._currentHistoryItem();
  8236. },
  8237.  
  8238. _currentHistoryItem: function()
  8239. {
  8240. return this._data[this._data.length - this._historyOffset];
  8241. },
  8242.  
  8243.  
  8244. defaultKeyHandler: function(event, force)
  8245. {
  8246. var newText;
  8247. var isPrevious;
  8248.  
  8249. switch (event.keyIdentifier) {
  8250. case "Up":
  8251. if (!this.isCaretOnFirstLine())
  8252. break;
  8253. newText = this._previous();
  8254. isPrevious = true;
  8255. break;
  8256. case "Down":
  8257. if (!this.isCaretOnLastLine())
  8258. break;
  8259. newText = this._next();
  8260. break;
  8261. case "U+0050": 
  8262. if (WebInspector.isMac() && event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey) {
  8263. newText = this._previous();
  8264. isPrevious = true;
  8265. }
  8266. break;
  8267. case "U+004E": 
  8268. if (WebInspector.isMac() && event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey)
  8269. newText = this._next();
  8270. break;
  8271. }
  8272.  
  8273. if (newText !== undefined) {
  8274. event.consume(true);
  8275. this.text = newText;
  8276.  
  8277. if (isPrevious) {
  8278. var firstNewlineIndex = this.text.indexOf("\n");
  8279. if (firstNewlineIndex === -1)
  8280. this.moveCaretToEndOfPrompt();
  8281. else {
  8282. var selection = window.getSelection();
  8283. var selectionRange = document.createRange();
  8284.  
  8285. selectionRange.setStart(this._element.firstChild, firstNewlineIndex);
  8286. selectionRange.setEnd(this._element.firstChild, firstNewlineIndex);
  8287.  
  8288. selection.removeAllRanges();
  8289. selection.addRange(selectionRange);
  8290. }
  8291. }
  8292.  
  8293. return true;
  8294. }
  8295.  
  8296. return WebInspector.TextPrompt.prototype.defaultKeyHandler.apply(this, arguments);
  8297. },
  8298.  
  8299. __proto__: WebInspector.TextPrompt.prototype
  8300. }
  8301.  
  8302.  
  8303. WebInspector.TextPrompt.SuggestBox = function(textPrompt, inputElement, className)
  8304. {
  8305. this._textPrompt = textPrompt;
  8306. this._inputElement = inputElement;
  8307. this._length = 0;
  8308. this._selectedIndex = -1;
  8309. this._selectedElement = null;
  8310. this._boundOnScroll = this._onscrollresize.bind(this, true);
  8311. this._boundOnResize = this._onscrollresize.bind(this, false);
  8312. window.addEventListener("scroll", this._boundOnScroll, true);
  8313. window.addEventListener("resize", this._boundOnResize, true);
  8314.  
  8315. this._bodyElement = inputElement.ownerDocument.body;
  8316. this._element = inputElement.ownerDocument.createElement("div");
  8317. this._element.className = "suggest-box " + (className || "");
  8318. this._element.addEventListener("mousedown", this._onboxmousedown.bind(this), true);
  8319. this.containerElement = this._element.createChild("div", "container");
  8320. this.contentElement = this.containerElement.createChild("div", "content");
  8321. }
  8322.  
  8323. WebInspector.TextPrompt.SuggestBox.prototype = {
  8324. get visible()
  8325. {
  8326. return !!this._element.parentElement;
  8327. },
  8328.  
  8329. get hasSelection()
  8330. {
  8331. return !!this._selectedElement;
  8332. },
  8333.  
  8334. _onscrollresize: function(isScroll, event)
  8335. {
  8336. if (isScroll && this._element.isAncestor(event.target) || !this.visible)
  8337. return;
  8338. this._updateBoxPositionWithExistingAnchor();
  8339. },
  8340.  
  8341. _updateBoxPositionWithExistingAnchor: function()
  8342. {
  8343. this._updateBoxPosition(this._anchorBox);
  8344. },
  8345.  
  8346.  
  8347. _updateBoxPosition: function(anchorBox)
  8348. {
  8349.  
  8350. this.contentElement.style.display = "inline-block";
  8351. document.body.appendChild(this.contentElement);
  8352. this.contentElement.positionAt(0, 0);
  8353. var contentWidth = this.contentElement.offsetWidth;
  8354. var contentHeight = this.contentElement.offsetHeight;
  8355. this.contentElement.style.display = "block";
  8356. this.containerElement.appendChild(this.contentElement);
  8357.  
  8358.  
  8359. this._anchorBox = anchorBox;
  8360. const spacer = 6;
  8361.  
  8362. const suggestBoxPaddingX = 21;
  8363. var maxWidth = document.body.offsetWidth - anchorBox.x - spacer;
  8364. var width = Math.min(contentWidth, maxWidth - suggestBoxPaddingX) + suggestBoxPaddingX;
  8365. var paddedWidth = contentWidth + suggestBoxPaddingX;
  8366. var boxX = anchorBox.x;
  8367. if (width < paddedWidth) {
  8368.  
  8369. maxWidth = document.body.offsetWidth - spacer;
  8370. width = Math.min(contentWidth, maxWidth - suggestBoxPaddingX) + suggestBoxPaddingX;
  8371. boxX = document.body.offsetWidth - width;
  8372. }
  8373.  
  8374. const suggestBoxPaddingY = 2;
  8375. var boxY;
  8376. var aboveHeight = anchorBox.y;
  8377. var underHeight = document.body.offsetHeight - anchorBox.y - anchorBox.height;
  8378. var maxHeight = Math.max(underHeight, aboveHeight) - spacer;
  8379. var height = Math.min(contentHeight, maxHeight - suggestBoxPaddingY) + suggestBoxPaddingY;
  8380. if (underHeight >= aboveHeight) {
  8381.  
  8382. boxY = anchorBox.y + anchorBox.height;
  8383. this._element.removeStyleClass("above-anchor");
  8384. this._element.addStyleClass("under-anchor");
  8385. } else {
  8386.  
  8387. boxY = anchorBox.y - height;
  8388. this._element.removeStyleClass("under-anchor");
  8389. this._element.addStyleClass("above-anchor");
  8390. }
  8391.  
  8392. this._element.positionAt(boxX, boxY);
  8393. this._element.style.width = width + "px";
  8394. this._element.style.height = height + "px";
  8395. },
  8396.  
  8397. _onboxmousedown: function(event)
  8398. {
  8399. event.preventDefault();
  8400. },
  8401.  
  8402. hide: function()
  8403. {
  8404. if (!this.visible)
  8405. return;
  8406.  
  8407. this._element.parentElement.removeChild(this._element);
  8408. delete this._selectedElement;
  8409. },
  8410.  
  8411. removeFromElement: function()
  8412. {
  8413. window.removeEventListener("scroll", this._boundOnScroll, true);
  8414. window.removeEventListener("resize", this._boundOnResize, true);
  8415. this.hide();
  8416. },
  8417.  
  8418.  
  8419. _applySuggestion: function(text, isIntermediateSuggestion)
  8420. {
  8421. if (!this.visible || !(text || this._selectedElement))
  8422. return false;
  8423.  
  8424. var suggestion = text || this._selectedElement.textContent;
  8425. if (!suggestion)
  8426. return false;
  8427.  
  8428. this._textPrompt.applySuggestion(suggestion, isIntermediateSuggestion);
  8429. return true;
  8430. },
  8431.  
  8432.  
  8433. acceptSuggestion: function(text)
  8434. {
  8435. var result = this._applySuggestion(text, false);
  8436. this.hide();
  8437. if (!result)
  8438. return false;
  8439.  
  8440. this._textPrompt.acceptSuggestion();
  8441.  
  8442. return true;
  8443. },
  8444.  
  8445.  
  8446. _selectClosest: function(shift, isCircular)
  8447. {
  8448. if (!this._length)
  8449. return false;
  8450.  
  8451. var index = this._selectedIndex + shift;
  8452.  
  8453. if (isCircular)
  8454. index = (this._length + index) % this._length;
  8455. else
  8456. index = Number.constrain(index, 0, this._length - 1);
  8457.  
  8458. this._selectItem(index);
  8459. this._applySuggestion(undefined, true);
  8460. return true;
  8461. },
  8462.  
  8463.  
  8464. updateSuggestions: function(anchorBox, completions, selectedIndex, canShowForSingleItem)
  8465. {
  8466. if (this._suggestTimeout) {
  8467. clearTimeout(this._suggestTimeout);
  8468. delete this._suggestTimeout;
  8469. }
  8470. this._completionsReady(anchorBox, completions, selectedIndex, canShowForSingleItem);
  8471. },
  8472.  
  8473. _onItemMouseDown: function(text, event)
  8474. {
  8475. this.acceptSuggestion(text);
  8476. event.consume(true);
  8477. },
  8478.  
  8479. _createItemElement: function(prefix, text)
  8480. {
  8481. var element = document.createElement("div");
  8482. element.className = "suggest-box-content-item source-code";
  8483. element.tabIndex = -1;
  8484. if (prefix && prefix.length && !text.indexOf(prefix)) {
  8485. var prefixElement = element.createChild("span", "prefix");
  8486. prefixElement.textContent = prefix;
  8487. var suffixElement = element.createChild("span", "suffix");
  8488. suffixElement.textContent = text.substring(prefix.length);
  8489. } else {
  8490. var suffixElement = element.createChild("span", "suffix");
  8491. suffixElement.textContent = text;
  8492. }
  8493. element.addEventListener("mousedown", this._onItemMouseDown.bind(this, text), false);
  8494. return element;
  8495. },
  8496.  
  8497.  
  8498. _updateItems: function(items, selectedIndex)
  8499. {
  8500. this._length = items.length;
  8501. this.contentElement.removeChildren();
  8502.  
  8503. var userEnteredText = this._textPrompt._userEnteredText;
  8504. for (var i = 0; i < items.length; ++i) {
  8505. var item = items[i];
  8506. var currentItemElement = this._createItemElement(userEnteredText, item);
  8507. this.contentElement.appendChild(currentItemElement);
  8508. }
  8509.  
  8510. this._selectedElement = null;
  8511. if (typeof selectedIndex === "number")
  8512. this._selectItem(selectedIndex);
  8513. },
  8514.  
  8515.  
  8516. _selectItem: function(index)
  8517. {
  8518. if (this._selectedElement)
  8519. this._selectedElement.classList.remove("selected");
  8520.  
  8521. this._selectedIndex = index;
  8522. this._selectedElement = this.contentElement.children[index];
  8523. this._selectedElement.classList.add("selected");
  8524.  
  8525. this._selectedElement.scrollIntoViewIfNeeded(false);
  8526. },
  8527.  
  8528.  
  8529. _canShowBox: function(completions, canShowForSingleItem)
  8530. {
  8531. if (!completions || !completions.length)
  8532. return false;
  8533.  
  8534. if (completions.length > 1)
  8535. return true;
  8536.  
  8537.  
  8538. return canShowForSingleItem && completions[0] !== this._textPrompt._userEnteredText;
  8539. },
  8540.  
  8541. _rememberRowCountPerViewport: function()
  8542. {
  8543. if (!this.contentElement.firstChild)
  8544. return;
  8545.  
  8546. this._rowCountPerViewport = Math.floor(this.containerElement.offsetHeight / this.contentElement.firstChild.offsetHeight);
  8547. },
  8548.  
  8549.  
  8550. _completionsReady: function(anchorBox, completions, selectedIndex, canShowForSingleItem)
  8551. {
  8552. if (this._canShowBox(completions, canShowForSingleItem)) {
  8553. this._updateItems(completions, selectedIndex);
  8554. this._updateBoxPosition(anchorBox);
  8555. if (!this.visible)
  8556. this._bodyElement.appendChild(this._element);
  8557. this._rememberRowCountPerViewport();
  8558. } else
  8559. this.hide();
  8560. },
  8561.  
  8562. upKeyPressed: function(event)
  8563. {
  8564. return this._selectClosest(-1, true);
  8565. },
  8566.  
  8567. downKeyPressed: function(event)
  8568. {
  8569. return this._selectClosest(1, true);
  8570. },
  8571.  
  8572. pageUpKeyPressed: function(event)
  8573. {
  8574. return this._selectClosest(-this._rowCountPerViewport, false);
  8575. },
  8576.  
  8577. pageDownKeyPressed: function(event)
  8578. {
  8579. return this._selectClosest(this._rowCountPerViewport, false);
  8580. },
  8581.  
  8582. enterKeyPressed: function(event)
  8583. {
  8584. var hasSelectedItem = !!this._selectedElement;
  8585. this.acceptSuggestion();
  8586.  
  8587.  
  8588.  
  8589. return hasSelectedItem;
  8590. },
  8591.  
  8592. tabKeyPressed: function(event)
  8593. {
  8594. return this.enterKeyPressed(event);
  8595. }
  8596. }
  8597.  
  8598.  
  8599.  
  8600.  
  8601.  
  8602.  
  8603. WebInspector.Popover = function(popoverHelper)
  8604. {
  8605. WebInspector.View.call(this);
  8606. this.markAsRoot();
  8607. this.element.className = "popover custom-popup-vertical-scroll custom-popup-horizontal-scroll";
  8608.  
  8609. this._popupArrowElement = document.createElement("div");
  8610. this._popupArrowElement.className = "arrow";
  8611. this.element.appendChild(this._popupArrowElement);
  8612.  
  8613. this._contentDiv = document.createElement("div");
  8614. this._contentDiv.className = "content";
  8615. this.element.appendChild(this._contentDiv);
  8616.  
  8617. this._popoverHelper = popoverHelper;
  8618. }
  8619.  
  8620. WebInspector.Popover.prototype = {
  8621.  
  8622. show: function(element, anchor, preferredWidth, preferredHeight)
  8623. {
  8624. this._innerShow(null, element, anchor, preferredWidth, preferredHeight);
  8625. },
  8626.  
  8627.  
  8628. showView: function(view, anchor, preferredWidth, preferredHeight)
  8629. {
  8630. this._innerShow(view, view.element, anchor, preferredWidth, preferredHeight);
  8631. },
  8632.  
  8633.  
  8634. _innerShow: function(view, contentElement, anchor, preferredWidth, preferredHeight)
  8635. {
  8636. if (this._disposed)
  8637. return;
  8638. this.contentElement = contentElement;
  8639.  
  8640.  
  8641. if (WebInspector.Popover._popover)
  8642. WebInspector.Popover._popover.detach();
  8643. WebInspector.Popover._popover = this;
  8644.  
  8645.  
  8646. var preferredSize = view ? view.measurePreferredSize() : this.contentElement.measurePreferredSize();
  8647. preferredWidth = preferredWidth || preferredSize.width;
  8648. preferredHeight = preferredHeight || preferredSize.height;
  8649.  
  8650. WebInspector.View.prototype.show.call(this, document.body);
  8651.  
  8652. if (view)
  8653. view.show(this._contentDiv);
  8654. else
  8655. this._contentDiv.appendChild(this.contentElement);
  8656.  
  8657. this._positionElement(anchor, preferredWidth, preferredHeight);
  8658.  
  8659. if (this._popoverHelper) {
  8660. contentElement.addEventListener("mousemove", this._popoverHelper._killHidePopoverTimer.bind(this._popoverHelper), true);
  8661. this.element.addEventListener("mouseout", this._popoverHelper._popoverMouseOut.bind(this._popoverHelper), true);
  8662. }
  8663. },
  8664.  
  8665. hide: function()
  8666. {
  8667. this.detach();
  8668. delete WebInspector.Popover._popover;
  8669. },
  8670.  
  8671. get disposed()
  8672. {
  8673. return this._disposed;
  8674. },
  8675.  
  8676. dispose: function()
  8677. {
  8678. if (this.isShowing())
  8679. this.hide();
  8680. this._disposed = true;
  8681. },
  8682.  
  8683. setCanShrink: function(canShrink)
  8684. {
  8685. this._hasFixedHeight = !canShrink;
  8686. this._contentDiv.addStyleClass("fixed-height");
  8687. },
  8688.  
  8689. _positionElement: function(anchorElement, preferredWidth, preferredHeight)
  8690. {
  8691. const borderWidth = 25;
  8692. const scrollerWidth = this._hasFixedHeight ? 0 : 11;
  8693. const arrowHeight = 15;
  8694. const arrowOffset = 10;
  8695. const borderRadius = 10;
  8696.  
  8697.  
  8698. preferredWidth = Math.max(preferredWidth, 50);
  8699. const totalWidth = window.innerWidth;
  8700. const totalHeight = window.innerHeight;
  8701.  
  8702. var anchorBox = anchorElement.boxInWindow(window);
  8703. var newElementPosition = { x: 0, y: 0, width: preferredWidth + scrollerWidth, height: preferredHeight };
  8704.  
  8705. var verticalAlignment;
  8706. var roomAbove = anchorBox.y;
  8707. var roomBelow = totalHeight - anchorBox.y - anchorBox.height;
  8708.  
  8709. if (roomAbove > roomBelow) {
  8710.  
  8711. if (anchorBox.y > newElementPosition.height + arrowHeight + borderRadius)
  8712. newElementPosition.y = anchorBox.y - newElementPosition.height - arrowHeight;
  8713. else {
  8714. newElementPosition.y = borderRadius;
  8715. newElementPosition.height = anchorBox.y - borderRadius * 2 - arrowHeight;
  8716. if (this._hasFixedHeight && newElementPosition.height < preferredHeight) {
  8717. newElementPosition.y = borderRadius;
  8718. newElementPosition.height = preferredHeight;
  8719. }
  8720. }
  8721. verticalAlignment = "bottom";
  8722. } else {
  8723.  
  8724. newElementPosition.y = anchorBox.y + anchorBox.height + arrowHeight;
  8725. if (newElementPosition.y + newElementPosition.height + arrowHeight - borderWidth >= totalHeight) {
  8726. newElementPosition.height = totalHeight - anchorBox.y - anchorBox.height - borderRadius * 2 - arrowHeight;
  8727. if (this._hasFixedHeight && newElementPosition.height < preferredHeight) {
  8728. newElementPosition.y = totalHeight - preferredHeight - borderRadius;
  8729. newElementPosition.height = preferredHeight;
  8730. }
  8731. }
  8732.  
  8733. verticalAlignment = "top";
  8734. }
  8735.  
  8736. var horizontalAlignment;
  8737. if (anchorBox.x + newElementPosition.width < totalWidth) {
  8738. newElementPosition.x = Math.max(borderRadius, anchorBox.x - borderRadius - arrowOffset);
  8739. horizontalAlignment = "left";
  8740. } else if (newElementPosition.width + borderRadius * 2 < totalWidth) {
  8741. newElementPosition.x = totalWidth - newElementPosition.width - borderRadius;
  8742. horizontalAlignment = "right";
  8743.  
  8744. var arrowRightPosition = Math.max(0, totalWidth - anchorBox.x - anchorBox.width - borderRadius - arrowOffset);
  8745. arrowRightPosition += anchorBox.width / 2;
  8746. arrowRightPosition = Math.min(arrowRightPosition, newElementPosition.width - borderRadius - arrowOffset);
  8747. this._popupArrowElement.style.right = arrowRightPosition + "px";
  8748. } else {
  8749. newElementPosition.x = borderRadius;
  8750. newElementPosition.width = totalWidth - borderRadius * 2;
  8751. newElementPosition.height += scrollerWidth;
  8752. horizontalAlignment = "left";
  8753. if (verticalAlignment === "bottom")
  8754. newElementPosition.y -= scrollerWidth;
  8755.  
  8756. this._popupArrowElement.style.left = Math.max(0, anchorBox.x - borderRadius * 2 - arrowOffset) + "px";
  8757. this._popupArrowElement.style.left += anchorBox.width / 2;
  8758. }
  8759.  
  8760. this.element.className = "popover custom-popup-vertical-scroll custom-popup-horizontal-scroll " + verticalAlignment + "-" + horizontalAlignment + "-arrow";
  8761. this.element.positionAt(newElementPosition.x - borderWidth, newElementPosition.y - borderWidth);
  8762. this.element.style.width = newElementPosition.width + borderWidth * 2 + "px";
  8763. this.element.style.height = newElementPosition.height + borderWidth * 2 + "px";
  8764. },
  8765.  
  8766. __proto__: WebInspector.View.prototype
  8767. }
  8768.  
  8769.  
  8770. WebInspector.PopoverHelper = function(panelElement, getAnchor, showPopover, onHide, disableOnClick)
  8771. {
  8772. this._panelElement = panelElement;
  8773. this._getAnchor = getAnchor;
  8774. this._showPopover = showPopover;
  8775. this._onHide = onHide;
  8776. this._disableOnClick = !!disableOnClick;
  8777. panelElement.addEventListener("mousedown", this._mouseDown.bind(this), false);
  8778. panelElement.addEventListener("mousemove", this._mouseMove.bind(this), false);
  8779. panelElement.addEventListener("mouseout", this._mouseOut.bind(this), false);
  8780. this.setTimeout(1000);
  8781. }
  8782.  
  8783. WebInspector.PopoverHelper.prototype = {
  8784. setTimeout: function(timeout)
  8785. {
  8786. this._timeout = timeout;
  8787. },
  8788.  
  8789. _mouseDown: function(event)
  8790. {
  8791. if (this._disableOnClick || !event.target.isSelfOrDescendant(this._hoverElement))
  8792. this.hidePopover();
  8793. else {
  8794. this._killHidePopoverTimer();
  8795. this._handleMouseAction(event, true);
  8796. }
  8797. },
  8798.  
  8799. _mouseMove: function(event)
  8800. {
  8801.  
  8802. if (event.target.isSelfOrDescendant(this._hoverElement))
  8803. return;
  8804.  
  8805. this._startHidePopoverTimer();
  8806. this._handleMouseAction(event, false);
  8807. },
  8808.  
  8809. _popoverMouseOut: function(event)
  8810. {
  8811. if (!this.isPopoverVisible())
  8812. return;
  8813. if (event.relatedTarget && !event.relatedTarget.isSelfOrDescendant(this._popover._contentDiv))
  8814. this._startHidePopoverTimer();
  8815. },
  8816.  
  8817. _mouseOut: function(event)
  8818. {
  8819. if (!this.isPopoverVisible())
  8820. return;
  8821. if (event.relatedTarget && !event.relatedTarget.isSelfOrDescendant(this._hoverElement))
  8822. this._startHidePopoverTimer();
  8823. },
  8824.  
  8825. _startHidePopoverTimer: function()
  8826. {
  8827.  
  8828. if (!this._popover || this._hidePopoverTimer)
  8829. return;
  8830.  
  8831. function doHide()
  8832. {
  8833. this._hidePopover();
  8834. delete this._hidePopoverTimer;
  8835. }
  8836. this._hidePopoverTimer = setTimeout(doHide.bind(this), this._timeout / 2);
  8837. },
  8838.  
  8839. _handleMouseAction: function(event, isMouseDown)
  8840. {
  8841. this._resetHoverTimer();
  8842. if (event.which && this._disableOnClick)
  8843. return;
  8844. this._hoverElement = this._getAnchor(event.target, event);
  8845. if (!this._hoverElement)
  8846. return;
  8847. const toolTipDelay = isMouseDown ? 0 : (this._popup ? this._timeout * 0.6 : this._timeout);
  8848. this._hoverTimer = setTimeout(this._mouseHover.bind(this, this._hoverElement), toolTipDelay);
  8849. },
  8850.  
  8851. _resetHoverTimer: function()
  8852. {
  8853. if (this._hoverTimer) {
  8854. clearTimeout(this._hoverTimer);
  8855. delete this._hoverTimer;
  8856. }
  8857. },
  8858.  
  8859. isPopoverVisible: function()
  8860. {
  8861. return !!this._popover;
  8862. },
  8863.  
  8864. hidePopover: function()
  8865. {
  8866. this._resetHoverTimer();
  8867. this._hidePopover();
  8868. },
  8869.  
  8870. _hidePopover: function()
  8871. {
  8872. if (!this._popover)
  8873. return;
  8874.  
  8875. if (this._onHide)
  8876. this._onHide();
  8877.  
  8878. this._popover.dispose();
  8879. delete this._popover;
  8880. this._hoverElement = null;
  8881. },
  8882.  
  8883. _mouseHover: function(element)
  8884. {
  8885. delete this._hoverTimer;
  8886.  
  8887. this._hidePopover();
  8888. this._popover = new WebInspector.Popover(this);
  8889. this._showPopover(element, this._popover);
  8890. },
  8891.  
  8892. _killHidePopoverTimer: function()
  8893. {
  8894. if (this._hidePopoverTimer) {
  8895. clearTimeout(this._hidePopoverTimer);
  8896. delete this._hidePopoverTimer;
  8897.  
  8898.  
  8899.  
  8900. this._resetHoverTimer();
  8901. }
  8902. }
  8903. }
  8904.  
  8905.  
  8906.  
  8907.  
  8908.  
  8909.  
  8910. WebInspector.Placard = function(title, subtitle)
  8911. {
  8912. this.element = document.createElement("div");
  8913. this.element.className = "placard";
  8914. this.element.placard = this;
  8915.  
  8916. this.titleElement = document.createElement("div");
  8917. this.titleElement.className = "title";
  8918.  
  8919. this.subtitleElement = document.createElement("div");
  8920. this.subtitleElement.className = "subtitle";
  8921.  
  8922. this.element.appendChild(this.subtitleElement);
  8923. this.element.appendChild(this.titleElement);
  8924.  
  8925. this.title = title;
  8926. this.subtitle = subtitle;
  8927. this.selected = false;
  8928. }
  8929.  
  8930. WebInspector.Placard.prototype = {
  8931.  
  8932. get title()
  8933. {
  8934. return this._title;
  8935. },
  8936.  
  8937. set title(x)
  8938. {
  8939. if (this._title === x)
  8940. return;
  8941. this._title = x;
  8942. this.titleElement.textContent = x;
  8943. },
  8944.  
  8945.  
  8946. get subtitle()
  8947. {
  8948. return this._subtitle;
  8949. },
  8950.  
  8951. set subtitle(x)
  8952. {
  8953. if (this._subtitle === x)
  8954. return;
  8955. this._subtitle = x;
  8956. this.subtitleElement.textContent = x;
  8957. },
  8958.  
  8959.  
  8960. get selected()
  8961. {
  8962. return this._selected;
  8963. },
  8964.  
  8965. set selected(x)
  8966. {
  8967. if (x)
  8968. this.select();
  8969. else
  8970. this.deselect();
  8971. },
  8972.  
  8973. select: function()
  8974. {
  8975. if (this._selected)
  8976. return;
  8977. this._selected = true;
  8978. this.element.addStyleClass("selected");
  8979. },
  8980.  
  8981. deselect: function()
  8982. {
  8983. if (!this._selected)
  8984. return;
  8985. this._selected = false;
  8986. this.element.removeStyleClass("selected");
  8987. },
  8988.  
  8989. toggleSelected: function()
  8990. {
  8991. this.selected = !this.selected;
  8992. },
  8993.  
  8994. discard: function()
  8995. {
  8996. }
  8997. }
  8998.  
  8999.  
  9000.  
  9001.  
  9002.  
  9003.  
  9004. WebInspector.TabbedPane = function()
  9005. {
  9006. WebInspector.View.call(this);
  9007. this.registerRequiredCSS("tabbedPane.css");
  9008. this.element.addStyleClass("tabbed-pane");
  9009. this._headerElement = this.element.createChild("div", "tabbed-pane-header");
  9010. this._headerContentsElement = this._headerElement.createChild("div", "tabbed-pane-header-contents");
  9011. this._tabsElement = this._headerContentsElement.createChild("div", "tabbed-pane-header-tabs");
  9012. this._contentElement = this.element.createChild("div", "tabbed-pane-content");
  9013. this._tabs = [];
  9014. this._tabsHistory = [];
  9015. this._tabsById = {};
  9016. this.element.addEventListener("click", this.focus.bind(this), false);
  9017. this.element.addEventListener("mouseup", this.onMouseUp.bind(this), false);
  9018.  
  9019. this._dropDownButton = this._createDropDownButton();
  9020. }
  9021.  
  9022. WebInspector.TabbedPane.EventTypes = {
  9023. TabSelected: "TabSelected",
  9024. TabClosed: "TabClosed"
  9025. }
  9026.  
  9027. WebInspector.TabbedPane.prototype = {
  9028.  
  9029. get visibleView()
  9030. {
  9031. return this._currentTab ? this._currentTab.view : null;
  9032. },
  9033.  
  9034.  
  9035. get selectedTabId()
  9036. {
  9037. return this._currentTab ? this._currentTab.id : null;
  9038. },
  9039.  
  9040.  
  9041. set shrinkableTabs(shrinkableTabs)
  9042. {
  9043. this._shrinkableTabs = shrinkableTabs;
  9044. },
  9045.  
  9046.  
  9047. set verticalTabLayout(verticalTabLayout)
  9048. {
  9049. this._verticalTabLayout = verticalTabLayout;
  9050. },
  9051.  
  9052.  
  9053. set closeableTabs(closeableTabs)
  9054. {
  9055. this._closeableTabs = closeableTabs;
  9056. },
  9057.  
  9058. defaultFocusedElement: function()
  9059. {
  9060. return this.visibleView ? this.visibleView.defaultFocusedElement() : null;
  9061. },
  9062.  
  9063.  
  9064. onMouseUp: function(event)
  9065. {
  9066.  
  9067. if (event.button === 1)
  9068. event.consume(true);
  9069. },
  9070.  
  9071.  
  9072. appendTab: function(id, tabTitle, view, tabTooltip, userGesture)
  9073. {
  9074. var tab = new WebInspector.TabbedPaneTab(this, id, tabTitle, this._closeableTabs, view, tabTooltip);
  9075. this._tabsById[id] = tab;
  9076.  
  9077. this._tabs.push(tab);
  9078. this._tabsHistory.push(tab);
  9079.  
  9080. if (this._tabsHistory[0] === tab)
  9081. this.selectTab(tab.id, userGesture);
  9082.  
  9083. this._updateTabElements();
  9084. },
  9085.  
  9086.  
  9087. closeTab: function(id, userGesture)
  9088. {
  9089. this._innerCloseTab(id, userGesture);
  9090. this._updateTabElements();
  9091. if (this._tabsHistory.length)
  9092. this.selectTab(this._tabsHistory[0].id, userGesture);
  9093. },
  9094.  
  9095.  
  9096. _innerCloseTab: function(id, userGesture)
  9097. {
  9098. if (this._currentTab && this._currentTab.id === id)
  9099. this._hideCurrentTab();
  9100.  
  9101. var tab = this._tabsById[id];
  9102. delete this._tabsById[id];
  9103.  
  9104. this._tabsHistory.splice(this._tabsHistory.indexOf(tab), 1);
  9105. this._tabs.splice(this._tabs.indexOf(tab), 1);
  9106. if (tab._shown)
  9107. this._hideTabElement(tab);
  9108.  
  9109. var eventData = { tabId: id, view: tab.view, isUserGesture: userGesture };
  9110. this.dispatchEventToListeners(WebInspector.TabbedPane.EventTypes.TabClosed, eventData);
  9111. return true;
  9112. },
  9113.  
  9114.  
  9115. closeAllTabs: function(userGesture)
  9116. {
  9117. var tabs = this._tabs.slice();
  9118. for (var i = 0; i < tabs.length; ++i)
  9119. this._innerCloseTab(tabs[i].id, userGesture);
  9120. this._updateTabElements();
  9121. },
  9122.  
  9123.  
  9124. closeOtherTabs: function(id)
  9125. {
  9126. var tabs = this._tabs.slice();
  9127. for (var i = 0; i < tabs.length; ++i) {
  9128. if (tabs[i].id !== id)
  9129. this._innerCloseTab(tabs[i].id, true);
  9130. }
  9131. this._updateTabElements();
  9132. this.selectTab(id, true);
  9133. },
  9134.  
  9135.  
  9136. selectTab: function(id, userGesture)
  9137. {
  9138. var tab = this._tabsById[id];
  9139. if (!tab)
  9140. return;
  9141. if (this._currentTab && this._currentTab.id === id)
  9142. return;
  9143.  
  9144. this._hideCurrentTab();
  9145. this._showTab(tab);
  9146. this._currentTab = tab;
  9147.  
  9148. this._tabsHistory.splice(this._tabsHistory.indexOf(tab), 1);
  9149. this._tabsHistory.splice(0, 0, tab);
  9150.  
  9151. this._updateTabElements();
  9152.  
  9153. var eventData = { tabId: id, view: tab.view, isUserGesture: userGesture };
  9154. this.dispatchEventToListeners(WebInspector.TabbedPane.EventTypes.TabSelected, eventData);
  9155. return true;
  9156. },
  9157.  
  9158.  
  9159. lastOpenedTabIds: function(tabsCount)
  9160. {
  9161. function tabToTabId(tab) {
  9162. return tab.id;
  9163. }
  9164.  
  9165. return this._tabsHistory.slice(0, tabsCount).map(tabToTabId);
  9166. },
  9167.  
  9168.  
  9169. changeTabTitle: function(id, tabTitle)
  9170. {
  9171. var tab = this._tabsById[id];
  9172. tab.title = tabTitle;
  9173. this._updateTabElements();
  9174. },
  9175.  
  9176.  
  9177. changeTabView: function(id, view)
  9178. {
  9179. var tab = this._tabsById[id];
  9180. if (this._currentTab && this._currentTab.id === tab.id) {
  9181. this._hideTab(tab);
  9182. tab.view = view;
  9183. this._showTab(tab);
  9184. } else
  9185. tab.view = view;
  9186. },
  9187.  
  9188.  
  9189. changeTabTooltip: function(id, tabTooltip)
  9190. {
  9191. var tab = this._tabsById[id];
  9192. tab.tooltip = tabTooltip;
  9193. },
  9194.  
  9195. onResize: function()
  9196. {
  9197. this._updateTabElements();
  9198. },
  9199.  
  9200. _updateTabElements: function()
  9201. {
  9202. WebInspector.invokeOnceAfterBatchUpdate(this, this._innerUpdateTabElements);
  9203. },
  9204.  
  9205. _innerUpdateTabElements: function()
  9206. {
  9207. if (!this.isShowing())
  9208. return;
  9209.  
  9210. if (!this._tabs.length)
  9211. this._contentElement.addStyleClass("has-no-tabs");
  9212. else
  9213. this._contentElement.removeStyleClass("has-no-tabs");
  9214.  
  9215. if (!this._measuredDropDownButtonWidth)
  9216. this._measureDropDownButton();
  9217.  
  9218. this._updateWidths();
  9219. this._updateTabsDropDown();
  9220. },
  9221.  
  9222.  
  9223. _showTabElement: function(index, tab)
  9224. {
  9225. if (index >= this._tabsElement.children.length)
  9226. this._tabsElement.appendChild(tab.tabElement);
  9227. else
  9228. this._tabsElement.insertBefore(tab.tabElement, this._tabsElement.children[index]);
  9229. tab._shown = true;
  9230. },
  9231.  
  9232.  
  9233. _hideTabElement: function(tab)
  9234. {
  9235. this._tabsElement.removeChild(tab.tabElement);
  9236. tab._shown = false;
  9237. },
  9238.  
  9239. _createDropDownButton: function()
  9240. {
  9241. var dropDownContainer = document.createElement("div");
  9242. dropDownContainer.addStyleClass("tabbed-pane-header-tabs-drop-down-container");
  9243. var dropDownButton = dropDownContainer.createChild("div", "tabbed-pane-header-tabs-drop-down");
  9244. dropDownButton.appendChild(document.createTextNode("\u00bb"));
  9245. this._tabsSelect = dropDownButton.createChild("select", "tabbed-pane-header-tabs-drop-down-select");
  9246. this._tabsSelect.addEventListener("change", this._tabsSelectChanged.bind(this), false);
  9247. return dropDownContainer;
  9248. },
  9249.  
  9250. _totalWidth: function()
  9251. {
  9252. return this._headerContentsElement.getBoundingClientRect().width;
  9253. },
  9254.  
  9255. _updateTabsDropDown: function()
  9256. {
  9257. var tabsToShowIndexes = this._tabsToShowIndexes(this._tabs, this._tabsHistory, this._totalWidth(), this._measuredDropDownButtonWidth);
  9258.  
  9259. for (var i = 0; i < this._tabs.length; ++i) {
  9260. if (this._tabs[i]._shown && tabsToShowIndexes.indexOf(i) === -1)
  9261. this._hideTabElement(this._tabs[i]);
  9262. }
  9263. for (var i = 0; i < tabsToShowIndexes.length; ++i) {
  9264. var tab = this._tabs[tabsToShowIndexes[i]];
  9265. if (!tab._shown)
  9266. this._showTabElement(i, tab);
  9267. }
  9268.  
  9269. this._populateDropDownFromIndex();
  9270. },
  9271.  
  9272. _populateDropDownFromIndex: function()
  9273. {
  9274. if (this._dropDownButton.parentElement)
  9275. this._headerContentsElement.removeChild(this._dropDownButton);
  9276.  
  9277. this._tabsSelect.removeChildren();
  9278. var tabsToShow = [];
  9279. for (var i = 0; i < this._tabs.length; ++i) {
  9280. if (!this._tabs[i]._shown)
  9281. tabsToShow.push(this._tabs[i]);
  9282. continue;
  9283. }
  9284.  
  9285. function compareFunction(tab1, tab2)
  9286. {
  9287. return tab1.title.localeCompare(tab2.title);
  9288. }
  9289. tabsToShow.sort(compareFunction);
  9290.  
  9291. for (var i = 0; i < tabsToShow.length; ++i) {
  9292. var option = new Option(tabsToShow[i].title);
  9293. option.tab = tabsToShow[i];
  9294. this._tabsSelect.appendChild(option);
  9295. }
  9296. if (this._tabsSelect.options.length) {
  9297. this._headerContentsElement.appendChild(this._dropDownButton);
  9298. this._tabsSelect.selectedIndex = -1;
  9299. }
  9300. },
  9301.  
  9302. _tabsSelectChanged: function()
  9303. {
  9304. var options = this._tabsSelect.options;
  9305. var selectedOption = options[this._tabsSelect.selectedIndex];
  9306. this.selectTab(selectedOption.tab.id, true);
  9307. },
  9308.  
  9309. _measureDropDownButton: function()
  9310. {
  9311. this._dropDownButton.addStyleClass("measuring");
  9312. this._headerContentsElement.appendChild(this._dropDownButton);
  9313. this._measuredDropDownButtonWidth = this._dropDownButton.getBoundingClientRect().width;
  9314. this._headerContentsElement.removeChild(this._dropDownButton);
  9315. this._dropDownButton.removeStyleClass("measuring");
  9316. },
  9317.  
  9318. _updateWidths: function()
  9319. {
  9320. var measuredWidths = this._measureWidths();
  9321. var maxWidth = this._shrinkableTabs ? this._calculateMaxWidth(measuredWidths.slice(), this._totalWidth()) : Number.MAX_VALUE;
  9322.  
  9323. var i = 0;
  9324. for (var tabId in this._tabs) {
  9325. var tab = this._tabs[tabId];
  9326. tab.setWidth(this._verticalTabLayout ? -1 : Math.min(maxWidth, measuredWidths[i++]));
  9327. }
  9328. },
  9329.  
  9330. _measureWidths: function()
  9331. {
  9332.  
  9333. var measuringTabElements = [];
  9334. for (var tabId in this._tabs) {
  9335. var tab = this._tabs[tabId];
  9336. if (typeof tab._measuredWidth === "number")
  9337. continue;
  9338. var measuringTabElement = tab._createTabElement(true);
  9339. measuringTabElement.__tab = tab;
  9340. measuringTabElements.push(measuringTabElement);
  9341. this._tabsElement.appendChild(measuringTabElement);
  9342. }
  9343.  
  9344.  
  9345. for (var i = 0; i < measuringTabElements.length; ++i)
  9346. measuringTabElements[i].__tab._measuredWidth = measuringTabElements[i].getBoundingClientRect().width;
  9347.  
  9348.  
  9349. for (var i = 0; i < measuringTabElements.length; ++i)
  9350. measuringTabElements[i].parentElement.removeChild(measuringTabElements[i]);
  9351.  
  9352.  
  9353. var measuredWidths = [];
  9354. for (var tabId in this._tabs)
  9355. measuredWidths.push(this._tabs[tabId]._measuredWidth);
  9356.  
  9357. return measuredWidths;
  9358. },
  9359.  
  9360.  
  9361. _calculateMaxWidth: function(measuredWidths, totalWidth)
  9362. {
  9363. if (!measuredWidths.length)
  9364. return 0;
  9365.  
  9366. measuredWidths.sort(function(x, y) { return x - y });
  9367.  
  9368. var totalMeasuredWidth = 0;
  9369. for (var i = 0; i < measuredWidths.length; ++i)
  9370. totalMeasuredWidth += measuredWidths[i];
  9371.  
  9372. if (totalWidth >= totalMeasuredWidth)
  9373. return measuredWidths[measuredWidths.length - 1];
  9374.  
  9375. var totalExtraWidth = 0;
  9376. for (var i = measuredWidths.length - 1; i > 0; --i) {
  9377. var extraWidth = measuredWidths[i] - measuredWidths[i - 1];
  9378. totalExtraWidth += (measuredWidths.length - i) * extraWidth;
  9379.  
  9380. if (totalWidth + totalExtraWidth >= totalMeasuredWidth)
  9381. return measuredWidths[i - 1] + (totalWidth + totalExtraWidth - totalMeasuredWidth) / (measuredWidths.length - i); 
  9382. }
  9383.  
  9384. return totalWidth / measuredWidths.length;
  9385. },
  9386.  
  9387.  
  9388. _tabsToShowIndexes: function(tabsOrdered, tabsHistory, totalWidth, measuredDropDownButtonWidth)
  9389. {
  9390. var tabsToShowIndexes = [];
  9391.  
  9392. var totalTabsWidth = 0;
  9393. for (var i = 0; i < tabsHistory.length; ++i) {
  9394. totalTabsWidth += tabsHistory[i].width();
  9395. var minimalRequiredWidth = totalTabsWidth;
  9396. if (i !== tabsHistory.length - 1)
  9397. minimalRequiredWidth += measuredDropDownButtonWidth;
  9398. if (!this._verticalTabLayout && minimalRequiredWidth > totalWidth)
  9399. break;
  9400. tabsToShowIndexes.push(tabsOrdered.indexOf(tabsHistory[i]));
  9401. }
  9402.  
  9403. tabsToShowIndexes.sort(function(x, y) { return x - y });
  9404.  
  9405. return tabsToShowIndexes;
  9406. },
  9407.  
  9408. _hideCurrentTab: function()
  9409. {
  9410. if (!this._currentTab)
  9411. return;
  9412.  
  9413. this._hideTab(this._currentTab);
  9414. delete this._currentTab;
  9415. },
  9416.  
  9417.  
  9418. _showTab: function(tab)
  9419. {
  9420. tab.tabElement.addStyleClass("selected");
  9421. tab.view.show(this._contentElement);
  9422. },
  9423.  
  9424.  
  9425. _hideTab: function(tab)
  9426. {
  9427. tab.tabElement.removeStyleClass("selected");
  9428. tab.view.detach();
  9429. },
  9430.  
  9431. canHighlightLine: function()
  9432. {
  9433. return this._currentTab && this._currentTab.view && this._currentTab.view.canHighlightLine();
  9434. },
  9435.  
  9436. highlightLine: function(line)
  9437. {
  9438. if (this.canHighlightLine())
  9439. this._currentTab.view.highlightLine(line);
  9440. },
  9441.  
  9442.  
  9443. elementsToRestoreScrollPositionsFor: function()
  9444. {
  9445. return [ this._contentElement ];
  9446. },
  9447.  
  9448.  
  9449. _insertBefore: function(tab, index)
  9450. {
  9451. this._tabsElement.insertBefore(tab._tabElement, this._tabsElement.childNodes[index]);
  9452. var oldIndex = this._tabs.indexOf(tab);
  9453. this._tabs.splice(oldIndex, 1);
  9454. if (oldIndex < index)
  9455. --index;
  9456. this._tabs.splice(index, 0, tab);
  9457. },
  9458.  
  9459. __proto__: WebInspector.View.prototype
  9460. }
  9461.  
  9462.  
  9463.  
  9464. WebInspector.TabbedPaneTab = function(tabbedPane, id, title, closeable, view, tooltip)
  9465. {
  9466. this._closeable = closeable;
  9467. this._tabbedPane = tabbedPane;
  9468. this._id = id;
  9469. this._title = title;
  9470. this._tooltip = tooltip;
  9471. this._view = view;
  9472. this._shown = false;
  9473. this._measuredWidth;
  9474. this._tabElement;
  9475. }
  9476.  
  9477. WebInspector.TabbedPaneTab.prototype = {
  9478.  
  9479. get id()
  9480. {
  9481. return this._id;
  9482. },
  9483.  
  9484.  
  9485. get title()
  9486. {
  9487. return this._title;
  9488. },
  9489.  
  9490. set title(title)
  9491. {
  9492. if (title === this._title)
  9493. return;
  9494. this._title = title;
  9495. if (this._titleElement)
  9496. this._titleElement.textContent = title;
  9497. delete this._measuredWidth;
  9498. },
  9499.  
  9500.  
  9501. get view()
  9502. {
  9503. return this._view;
  9504. },
  9505.  
  9506. set view(view)
  9507. {
  9508. this._view = view;
  9509. },
  9510.  
  9511.  
  9512. get tooltip()
  9513. {
  9514. return this._tooltip;
  9515. },
  9516.  
  9517. set tooltip(tooltip)
  9518. {
  9519. this._tooltip = tooltip;
  9520. if (this._titleElement)
  9521. this._titleElement.title = tooltip || "";
  9522. },
  9523.  
  9524.  
  9525. get tabElement()
  9526. {
  9527. if (typeof(this._tabElement) !== "undefined")
  9528. return this._tabElement;
  9529.  
  9530. this._createTabElement(false);
  9531. return this._tabElement;
  9532. },
  9533.  
  9534.  
  9535. width: function()
  9536. {
  9537. return this._width;
  9538. },
  9539.  
  9540.  
  9541. setWidth: function(width)
  9542. {
  9543. this.tabElement.style.width = width === -1 ? "" : (width + "px");
  9544. this._width = width;
  9545. },
  9546.  
  9547.  
  9548. _createTabElement: function(measuring)
  9549. {
  9550. var tabElement = document.createElement("div");
  9551. tabElement.addStyleClass("tabbed-pane-header-tab");
  9552. tabElement.id = "tab-" + this._id;
  9553. tabElement.tabIndex = -1;
  9554.  
  9555. var titleElement = tabElement.createChild("span", "tabbed-pane-header-tab-title");
  9556. titleElement.textContent = this.title;
  9557. titleElement.title = this.tooltip || "";
  9558. if (!measuring)
  9559. this._titleElement = titleElement;
  9560.  
  9561. if (this._closeable) {
  9562. var closeButtonSpan = tabElement.createChild("span", "tabbed-pane-header-tab-close-button");
  9563. closeButtonSpan.textContent = "\u00D7"; 
  9564. }
  9565.  
  9566. if (measuring)
  9567. tabElement.addStyleClass("measuring");
  9568. else {
  9569. this._tabElement = tabElement;
  9570. tabElement.addEventListener("click", this._tabClicked.bind(this), false);
  9571. tabElement.addEventListener("mousedown", this._tabMouseDown.bind(this), false);
  9572. if (this._closeable) {
  9573. tabElement.addEventListener("contextmenu", this._tabContextMenu.bind(this), false);
  9574. WebInspector.installDragHandle(tabElement, this._startTabDragging.bind(this), this._tabDragging.bind(this), this._endTabDragging.bind(this), "pointer");
  9575. }
  9576. }
  9577.  
  9578. return tabElement;
  9579. },
  9580.  
  9581.  
  9582. _tabClicked: function(event)
  9583. {
  9584. if (this._closeable && (event.button === 1 || event.target.hasStyleClass("tabbed-pane-header-tab-close-button")))
  9585. this._tabbedPane.closeTab(this.id, true);
  9586. },
  9587.  
  9588.  
  9589. _tabMouseDown: function(event)
  9590. {
  9591. if (event.target.hasStyleClass("tabbed-pane-header-tab-close-button") || event.button === 1)
  9592. return;
  9593. this._tabbedPane.selectTab(this.id, true);
  9594. },
  9595.  
  9596. _tabContextMenu: function(event)
  9597. {
  9598. function close()
  9599. {
  9600. this._tabbedPane.closeTab(this.id, true);
  9601. }
  9602.  
  9603. function closeOthers()
  9604. {
  9605. this._tabbedPane.closeOtherTabs(this.id);
  9606. }
  9607.  
  9608. function closeAll()
  9609. {
  9610. this._tabbedPane.closeAllTabs(true);
  9611. }
  9612.  
  9613. var contextMenu = new WebInspector.ContextMenu(event);
  9614. contextMenu.appendItem(WebInspector.UIString("Close"), close.bind(this));
  9615. contextMenu.appendItem(WebInspector.UIString("Close Others"), closeOthers.bind(this));
  9616. contextMenu.appendItem(WebInspector.UIString("Close All"), closeAll.bind(this));
  9617. contextMenu.show();
  9618. },
  9619.  
  9620.  
  9621. _startTabDragging: function(event)
  9622. {
  9623. if (event.target.hasStyleClass("tabbed-pane-header-tab-close-button"))
  9624. return false;
  9625. this._dragStartX = event.pageX;
  9626. return true;
  9627. },
  9628.  
  9629.  
  9630. _tabDragging: function(event)
  9631. {
  9632. var tabElements = this._tabbedPane._tabsElement.childNodes;
  9633. for (var i = 0; i < tabElements.length; ++i) {
  9634. var tabElement = tabElements[i];
  9635. if (tabElement === this._tabElement)
  9636. continue;
  9637.  
  9638. var intersects = tabElement.offsetLeft + tabElement.clientWidth > this._tabElement.offsetLeft &&
  9639. this._tabElement.offsetLeft + this._tabElement.clientWidth > tabElement.offsetLeft;
  9640. if (!intersects)
  9641. continue;
  9642.  
  9643. if (Math.abs(event.pageX - this._dragStartX) < tabElement.clientWidth / 2 + 5)
  9644. break;
  9645.  
  9646. if (event.pageX - this._dragStartX > 0) {
  9647. tabElement = tabElement.nextSibling;
  9648. ++i;
  9649. }
  9650.  
  9651. var oldOffsetLeft = this._tabElement.offsetLeft;
  9652. this._tabbedPane._insertBefore(this, i);
  9653. this._dragStartX += this._tabElement.offsetLeft - oldOffsetLeft;
  9654. break;
  9655. }
  9656.  
  9657. if (!this._tabElement.previousSibling && event.pageX - this._dragStartX < 0) {
  9658. this._tabElement.style.setProperty("left", "0px");
  9659. return;
  9660. }
  9661. if (!this._tabElement.nextSibling && event.pageX - this._dragStartX > 0) {
  9662. this._tabElement.style.setProperty("left", "0px");
  9663. return;
  9664. }
  9665.  
  9666. this._tabElement.style.setProperty("position", "relative");
  9667. this._tabElement.style.setProperty("left", (event.pageX - this._dragStartX) + "px");
  9668. },
  9669.  
  9670.  
  9671. _endTabDragging: function(event)
  9672. {
  9673. this._tabElement.style.removeProperty("position");
  9674. this._tabElement.style.removeProperty("left");
  9675. delete this._dragStartX;
  9676. }
  9677. }
  9678.  
  9679.  
  9680.  
  9681.  
  9682.  
  9683.  
  9684. WebInspector.Drawer = function()
  9685. {
  9686. this.element = document.getElementById("drawer");
  9687. this._savedHeight = 200; 
  9688. this._mainElement = document.getElementById("main");
  9689. this._toolbarElement = document.getElementById("toolbar");
  9690.  
  9691. this._floatingStatusBarContainer = document.getElementById("floating-status-bar-container");
  9692. WebInspector.installDragHandle(this._floatingStatusBarContainer, this._startStatusBarDragging.bind(this), this._statusBarDragging.bind(this), this._endStatusBarDragging.bind(this), "row-resize");
  9693.  
  9694. this._drawerContentsElement = document.createElement("div");
  9695. this._drawerContentsElement.id = "drawer-contents";
  9696. this._drawerContentsElement.className = "drawer-contents";
  9697. this.element.appendChild(this._drawerContentsElement);
  9698. this._viewStatusBar = document.createElement("div");
  9699. this._bottomStatusBar = document.getElementById("bottom-status-bar-container");
  9700. }
  9701.  
  9702. WebInspector.Drawer.AnimationType = {
  9703. Immediately: 0,
  9704. Normal: 1,
  9705. Slow: 2
  9706. }
  9707.  
  9708. WebInspector.Drawer.prototype = {
  9709. get visible()
  9710. {
  9711. return !!this._view;
  9712. },
  9713.  
  9714. _constrainHeight: function(height)
  9715. {
  9716. return Number.constrain(height, Preferences.minConsoleHeight, window.innerHeight - this._mainElement.totalOffsetTop() - Preferences.minConsoleHeight);
  9717. },
  9718.  
  9719. show: function(view, animationType)
  9720. {
  9721. this.immediatelyFinishAnimation();
  9722.  
  9723. var drawerWasVisible = this.visible;
  9724.  
  9725. if (this._view) {
  9726. this._view.detach();
  9727. this._drawerContentsElement.removeChildren();
  9728. }
  9729.  
  9730. this._view = view;
  9731.  
  9732. var statusBarItems = this._view.statusBarItems || [];
  9733. this._viewStatusBar.removeChildren();
  9734. for (var i = 0; i < statusBarItems.length; ++i)
  9735. this._viewStatusBar.appendChild(statusBarItems[i]);
  9736.  
  9737. document.body.addStyleClass("drawer-visible");
  9738. this._floatingStatusBarContainer.insertBefore(document.getElementById("panel-status-bar"), this._floatingStatusBarContainer.firstElementChild);
  9739. this._bottomStatusBar.appendChild(this._viewStatusBar);
  9740. this._view.markAsRoot();
  9741. this._view.show(this._drawerContentsElement);
  9742.  
  9743. if (drawerWasVisible)
  9744. return;
  9745.  
  9746. var height = this._constrainHeight(this._savedHeight || this.element.offsetHeight);
  9747. var animations = [
  9748. {element: this.element, end: {height: height}},
  9749. {element: this._mainElement, end: {bottom: height}},
  9750. {element: this._floatingStatusBarContainer, start: {"padding-left": this._bottomStatusBar.offsetLeft}, end: {"padding-left": 0}},
  9751. {element: this._viewStatusBar, start: {opacity: 0}, end: {opacity: 1}}
  9752. ];
  9753.  
  9754. function animationFinished()
  9755. {
  9756. WebInspector.inspectorView.currentPanel().doResize();
  9757. if (this._view && this._view.afterShow)
  9758. this._view.afterShow();
  9759. delete this._currentAnimation;
  9760. }
  9761.  
  9762. this._currentAnimation = WebInspector.animateStyle(animations, this._animationDuration(animationType), animationFinished.bind(this));
  9763. if (animationType === WebInspector.Drawer.AnimationType.Immediately)
  9764. this._currentAnimation.forceComplete();
  9765. },
  9766.  
  9767. hide: function(animationType)
  9768. {
  9769. this.immediatelyFinishAnimation();
  9770. if (!this.visible)
  9771. return;
  9772.  
  9773. this._savedHeight = this.element.offsetHeight;
  9774.  
  9775. WebInspector.restoreFocusFromElement(this.element);
  9776.  
  9777.  
  9778.  
  9779. document.body.removeStyleClass("drawer-visible");
  9780. WebInspector.inspectorView.currentPanel().statusBarResized();
  9781. document.body.addStyleClass("drawer-visible");
  9782.  
  9783. var animations = [
  9784. {element: this._mainElement, end: {bottom: 0}},
  9785. {element: this.element, end: {height: 0}},
  9786. {element: this._floatingStatusBarContainer, start: {"padding-left": 0}, end: {"padding-left": this._bottomStatusBar.offsetLeft} },
  9787. {element: this._viewStatusBar, start: {opacity: 1}, end: {opacity: 0}}
  9788. ];
  9789.  
  9790. function animationFinished()
  9791. {
  9792. WebInspector.inspectorView.currentPanel().doResize();
  9793. this._view.detach();
  9794. delete this._view;
  9795. this._bottomStatusBar.removeChildren();
  9796. this._bottomStatusBar.appendChild(document.getElementById("panel-status-bar"));
  9797. this._drawerContentsElement.removeChildren();
  9798. document.body.removeStyleClass("drawer-visible");
  9799. delete this._currentAnimation;
  9800. }
  9801.  
  9802. this._currentAnimation = WebInspector.animateStyle(animations, this._animationDuration(animationType), animationFinished.bind(this));
  9803. if (animationType === WebInspector.Drawer.AnimationType.Immediately)
  9804. this._currentAnimation.forceComplete();
  9805. },
  9806.  
  9807. resize: function()
  9808. {
  9809. if (!this.visible)
  9810. return;
  9811.  
  9812. this._view.storeScrollPositions();
  9813. var height = this._constrainHeight(parseInt(this.element.style.height, 10));
  9814. this._mainElement.style.bottom = height + "px";
  9815. this.element.style.height = height + "px";
  9816. this._view.doResize();
  9817. },
  9818.  
  9819. immediatelyFinishAnimation: function()
  9820. {
  9821. if (this._currentAnimation)
  9822. this._currentAnimation.forceComplete();
  9823. },
  9824.  
  9825. _animationDuration: function(animationType)
  9826. {
  9827. switch (animationType) {
  9828. case WebInspector.Drawer.AnimationType.Slow:
  9829. return 2000;
  9830. case WebInspector.Drawer.AnimationType.Normal:
  9831. return 250;
  9832. default:
  9833. return 0;
  9834. }
  9835. },
  9836.  
  9837.  
  9838. _startStatusBarDragging: function(event)
  9839. {
  9840. if (!this.visible || event.target !== this._floatingStatusBarContainer)
  9841. return false;
  9842.  
  9843. this._view.storeScrollPositions();
  9844. this._statusBarDragOffset = event.pageY - this.element.totalOffsetTop();
  9845. return true;
  9846. },
  9847.  
  9848. _statusBarDragging: function(event)
  9849. {
  9850. var height = window.innerHeight - event.pageY + this._statusBarDragOffset;
  9851. height = Number.constrain(height, Preferences.minConsoleHeight, window.innerHeight - this._mainElement.totalOffsetTop() - Preferences.minConsoleHeight);
  9852.  
  9853. this._mainElement.style.bottom = height + "px";
  9854. this.element.style.height = height + "px";
  9855. if (WebInspector.inspectorView.currentPanel())
  9856. WebInspector.inspectorView.currentPanel().doResize();
  9857. this._view.doResize();
  9858.  
  9859. event.consume(true);
  9860. },
  9861.  
  9862. _endStatusBarDragging: function(event)
  9863. {
  9864. this._savedHeight = this.element.offsetHeight;
  9865. delete this._statusBarDragOffset;
  9866.  
  9867. event.consume();
  9868. }
  9869. }
  9870.  
  9871.  
  9872. WebInspector.drawer = null;
  9873.  
  9874.  
  9875.  
  9876.  
  9877.  
  9878.  
  9879. WebInspector.ConsoleModel = function()
  9880. {
  9881. this.messages = [];
  9882. this.warnings = 0;
  9883. this.errors = 0;
  9884. this._interruptRepeatCount = false;
  9885. InspectorBackend.registerConsoleDispatcher(new WebInspector.ConsoleDispatcher(this));
  9886. }
  9887.  
  9888. WebInspector.ConsoleModel.Events = {
  9889. ConsoleCleared: "console-cleared",
  9890. MessageAdded: "console-message-added",
  9891. RepeatCountUpdated: "repeat-count-updated"
  9892. }
  9893.  
  9894. WebInspector.ConsoleModel.prototype = {
  9895. enableAgent: function()
  9896. {
  9897. if (WebInspector.settings.monitoringXHREnabled.get())
  9898. ConsoleAgent.setMonitoringXHREnabled(true);
  9899.  
  9900. this._enablingConsole = true;
  9901. function callback()
  9902. {
  9903. delete this._enablingConsole;
  9904. }
  9905. ConsoleAgent.enable(callback.bind(this));
  9906. },
  9907.  
  9908.  
  9909. enablingConsole: function()
  9910. {
  9911. return !!this._enablingConsole;
  9912. },
  9913.  
  9914.  
  9915. addMessage: function(msg)
  9916. {
  9917. this.messages.push(msg);
  9918. this._previousMessage = msg;
  9919. this._incrementErrorWarningCount(msg);
  9920. this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.MessageAdded, msg);
  9921. this._interruptRepeatCount = false;
  9922. },
  9923.  
  9924.  
  9925. _incrementErrorWarningCount: function(msg)
  9926. {
  9927. switch (msg.level) {
  9928. case WebInspector.ConsoleMessage.MessageLevel.Warning:
  9929. this.warnings += msg.repeatDelta;
  9930. break;
  9931. case WebInspector.ConsoleMessage.MessageLevel.Error:
  9932. this.errors += msg.repeatDelta;
  9933. break;
  9934. }
  9935. },
  9936.  
  9937. requestClearMessages: function()
  9938. {
  9939. ConsoleAgent.clearMessages();
  9940. this.clearMessages();
  9941. },
  9942.  
  9943. clearMessages: function()
  9944. {
  9945. this.messages = [];
  9946.  
  9947. this.errors = 0;
  9948. this.warnings = 0;
  9949.  
  9950. this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.ConsoleCleared);
  9951. },
  9952.  
  9953. interruptRepeatCount: function()
  9954. {
  9955. this._interruptRepeatCount = true;
  9956. },
  9957.  
  9958.  
  9959. _messageRepeatCountUpdated: function(count)
  9960. {
  9961. var msg = this._previousMessage;
  9962. if (!msg)
  9963. return;
  9964.  
  9965. var prevRepeatCount = msg.totalRepeatCount;
  9966.  
  9967. if (!this._interruptRepeatCount) {
  9968. msg.repeatDelta = count - prevRepeatCount;
  9969. msg.repeatCount = msg.repeatCount + msg.repeatDelta;
  9970. msg.totalRepeatCount = count;
  9971. msg.updateRepeatCount();
  9972.  
  9973. this._incrementErrorWarningCount(msg);
  9974. this.dispatchEventToListeners(WebInspector.ConsoleModel.Events.RepeatCountUpdated, msg);
  9975. } else {
  9976. var msgCopy = msg.clone();
  9977. msgCopy.totalRepeatCount = count;
  9978. msgCopy.repeatCount = (count - prevRepeatCount) || 1;
  9979. msgCopy.repeatDelta = msgCopy.repeatCount;
  9980. this.addMessage(msgCopy);
  9981. }
  9982. },
  9983.  
  9984. __proto__: WebInspector.Object.prototype
  9985. }
  9986.  
  9987.  
  9988. WebInspector.ConsoleMessage = function(source, level, url, line, repeatCount)
  9989. {
  9990. this.source = source;
  9991. this.level = level;
  9992. this.url = url || null;
  9993. this.line = line || 0;
  9994. this.message = "";
  9995.  
  9996. repeatCount = repeatCount || 1;
  9997. this.repeatCount = repeatCount;
  9998. this.repeatDelta = repeatCount;
  9999. this.totalRepeatCount = repeatCount;
  10000. }
  10001.  
  10002. WebInspector.ConsoleMessage.prototype = {
  10003.  
  10004. isErrorOrWarning: function()
  10005. {
  10006. return (this.level === WebInspector.ConsoleMessage.MessageLevel.Warning || this.level === WebInspector.ConsoleMessage.MessageLevel.Error);
  10007. },
  10008.  
  10009. updateRepeatCount: function()
  10010. {
  10011.  
  10012. },
  10013.  
  10014.  
  10015. clone: function()
  10016. {
  10017.  
  10018. },
  10019.  
  10020. location: function()
  10021. {
  10022.  
  10023. }
  10024. }
  10025.  
  10026.  
  10027. WebInspector.ConsoleMessage.create = function(source, level, message, type, url, line, repeatCount, parameters, stackTrace, requestId, isOutdated)
  10028. {
  10029. }
  10030.  
  10031.  
  10032. WebInspector.ConsoleMessage.MessageSource = {
  10033. HTML: "html",
  10034. XML: "xml",
  10035. JS: "javascript",
  10036. Network: "network",
  10037. ConsoleAPI: "console-api",
  10038. Other: "other"
  10039. }
  10040.  
  10041. WebInspector.ConsoleMessage.MessageType = {
  10042. Log: "log",
  10043. Dir: "dir",
  10044. DirXML: "dirxml",
  10045. Trace: "trace",
  10046. Clear: "clear",
  10047. StartGroup: "startGroup",
  10048. StartGroupCollapsed: "startGroupCollapsed",
  10049. EndGroup: "endGroup",
  10050. Assert: "assert",
  10051. Result: "result"
  10052. }
  10053.  
  10054. WebInspector.ConsoleMessage.MessageLevel = {
  10055. Tip: "tip",
  10056. Log: "log",
  10057. Warning: "warning",
  10058. Error: "error",
  10059. Debug: "debug"
  10060. }
  10061.  
  10062.  
  10063.  
  10064. WebInspector.ConsoleDispatcher = function(console)
  10065. {
  10066. this._console = console;
  10067. }
  10068.  
  10069. WebInspector.ConsoleDispatcher.prototype = {
  10070.  
  10071. messageAdded: function(payload)
  10072. {
  10073. var consoleMessage = WebInspector.ConsoleMessage.create(
  10074. payload.source,
  10075. payload.level,
  10076. payload.text,
  10077. payload.type,
  10078. payload.url,
  10079. payload.line,
  10080. payload.repeatCount,
  10081. payload.parameters,
  10082. payload.stackTrace,
  10083. payload.networkRequestId,
  10084. this._console._enablingConsole);
  10085. this._console.addMessage(consoleMessage);
  10086. },
  10087.  
  10088.  
  10089. messageRepeatCountUpdated: function(count)
  10090. {
  10091. this._console._messageRepeatCountUpdated(count);
  10092. },
  10093.  
  10094. messagesCleared: function()
  10095. {
  10096. if (!WebInspector.settings.preserveConsoleLog.get())
  10097. this._console.clearMessages();
  10098. }
  10099. }
  10100.  
  10101.  
  10102. WebInspector.console = null;
  10103.  
  10104.  
  10105.  
  10106.  
  10107.  
  10108.  
  10109. WebInspector.ConsoleMessageImpl = function(source, level, message, linkifier, type, url, line, repeatCount, parameters, stackTrace, requestId, isOutdated)
  10110. {
  10111. WebInspector.ConsoleMessage.call(this, source, level, url, line, repeatCount);
  10112.  
  10113. this._linkifier = linkifier;
  10114. this.type = type || WebInspector.ConsoleMessage.MessageType.Log;
  10115. this._messageText = message;
  10116. this._parameters = parameters;
  10117. this._stackTrace = stackTrace;
  10118. this._request = requestId ? WebInspector.networkLog.requestForId(requestId) : null;
  10119. this._isOutdated = isOutdated;
  10120.  
  10121. this._customFormatters = {
  10122. "object": this._formatParameterAsObject,
  10123. "array":  this._formatParameterAsArray,
  10124. "node":   this._formatParameterAsNode,
  10125. "string": this._formatParameterAsString
  10126. };
  10127. }
  10128.  
  10129. WebInspector.ConsoleMessageImpl.prototype = {
  10130. _formatMessage: function()
  10131. {
  10132. this._formattedMessage = document.createElement("span");
  10133. this._formattedMessage.className = "console-message-text source-code";
  10134.  
  10135. if (this.source === WebInspector.ConsoleMessage.MessageSource.ConsoleAPI) {
  10136. switch (this.type) {
  10137. case WebInspector.ConsoleMessage.MessageType.Trace:
  10138. this._messageElement = document.createTextNode("console.trace()");
  10139. break;
  10140. case WebInspector.ConsoleMessage.MessageType.Clear:
  10141. this._messageElement = document.createTextNode(WebInspector.UIString("Console was cleared"));
  10142. this._formattedMessage.addStyleClass("console-info");
  10143. break;
  10144. case WebInspector.ConsoleMessage.MessageType.Assert:
  10145. var args = [WebInspector.UIString("Assertion failed:")];
  10146. if (this._parameters)
  10147. args = args.concat(this._parameters);
  10148. this._messageElement = this._format(args);
  10149. break;
  10150. case WebInspector.ConsoleMessage.MessageType.Dir:
  10151. var obj = this._parameters ? this._parameters[0] : undefined;
  10152. var args = ["%O", obj];
  10153. this._messageElement = this._format(args);
  10154. break;
  10155. default:
  10156. var args = this._parameters || [this._messageText];
  10157. this._messageElement = this._format(args);
  10158. }
  10159. } else if (this.source === WebInspector.ConsoleMessage.MessageSource.Network) {
  10160. if (this._request) {
  10161. this._stackTrace = this._request.initiator.stackTrace;
  10162. if (this._request.initiator && this._request.initiator.url) {
  10163. this.url = this._request.initiator.url;
  10164. this.line = this._request.initiator.lineNumber;
  10165. }
  10166. this._messageElement = document.createElement("span");
  10167. if (this.level === WebInspector.ConsoleMessage.MessageLevel.Error) {
  10168. this._messageElement.appendChild(document.createTextNode(this._request.requestMethod + " "));
  10169. this._messageElement.appendChild(WebInspector.linkifyRequestAsNode(this._request));
  10170. if (this._request.failed)
  10171. this._messageElement.appendChild(document.createTextNode(" " + this._request.localizedFailDescription));
  10172. else
  10173. this._messageElement.appendChild(document.createTextNode(" " + this._request.statusCode + " (" + this._request.statusText + ")"));
  10174. } else {
  10175. var fragment = WebInspector.linkifyStringAsFragmentWithCustomLinkifier(this._messageText, WebInspector.linkifyRequestAsNode.bind(null, this._request, ""));
  10176. this._messageElement.appendChild(fragment);
  10177. }
  10178. } else {
  10179. if (this.url) {
  10180. var isExternal = !WebInspector.resourceForURL(this.url);
  10181. this._anchorElement = WebInspector.linkifyURLAsNode(this.url, this.url, "console-message-url", isExternal);
  10182. }
  10183. this._messageElement = this._format([this._messageText]);
  10184. }
  10185. } else {
  10186. var args = this._parameters || [this._messageText];
  10187. this._messageElement = this._format(args);
  10188. }
  10189.  
  10190. if (this.source !== WebInspector.ConsoleMessage.MessageSource.Network || this._request) {
  10191. if (this._stackTrace && this._stackTrace.length && this._stackTrace[0].url) {
  10192. this._anchorElement = this._linkifyCallFrame(this._stackTrace[0]);
  10193. } else if (this.url && this.url !== "undefined") {
  10194. this._anchorElement = this._linkifyLocation(this.url, this.line, 0);
  10195. }
  10196. }
  10197.  
  10198. this._formattedMessage.appendChild(this._messageElement);
  10199. if (this._anchorElement) {
  10200. this._formattedMessage.appendChild(document.createTextNode(" "));
  10201. this._formattedMessage.appendChild(this._anchorElement);
  10202. }
  10203.  
  10204. var dumpStackTrace = !!this._stackTrace && this._stackTrace.length && (this.source === WebInspector.ConsoleMessage.MessageSource.Network || this.level === WebInspector.ConsoleMessage.MessageLevel.Error || this.type === WebInspector.ConsoleMessage.MessageType.Trace);
  10205. if (dumpStackTrace) {
  10206. var ol = document.createElement("ol");
  10207. ol.className = "outline-disclosure";
  10208. var treeOutline = new TreeOutline(ol);
  10209.  
  10210. var content = this._formattedMessage;
  10211. var root = new TreeElement(content, null, true);
  10212. content.treeElementForTest = root;
  10213. treeOutline.appendChild(root);
  10214. if (this.type === WebInspector.ConsoleMessage.MessageType.Trace)
  10215. root.expand();
  10216.  
  10217. this._populateStackTraceTreeElement(root);
  10218. this._formattedMessage = ol;
  10219. }
  10220.  
  10221.  
  10222. this._message = this._messageElement.textContent;
  10223. },
  10224.  
  10225. get message()
  10226. {
  10227.  
  10228. var formattedMessage = this.formattedMessage;
  10229. return this._message;
  10230. },
  10231.  
  10232. get formattedMessage()
  10233. {
  10234. if (!this._formattedMessage)
  10235. this._formatMessage();
  10236. return this._formattedMessage;
  10237. },
  10238.  
  10239. _linkifyLocation: function(url, lineNumber, columnNumber)
  10240. {
  10241.  
  10242. lineNumber = lineNumber ? lineNumber - 1 : 0;
  10243. columnNumber = columnNumber ? columnNumber - 1 : 0;
  10244. return this._linkifier.linkifyLocation(url, lineNumber, columnNumber, "console-message-url");
  10245. },
  10246.  
  10247. _linkifyCallFrame: function(callFrame)
  10248. {
  10249. return this._linkifyLocation(callFrame.url, callFrame.lineNumber, callFrame.columnNumber);
  10250. },
  10251.  
  10252. isErrorOrWarning: function()
  10253. {
  10254. return (this.level === WebInspector.ConsoleMessage.MessageLevel.Warning || this.level === WebInspector.ConsoleMessage.MessageLevel.Error);
  10255. },
  10256.  
  10257. _format: function(parameters)
  10258. {
  10259.  
  10260. var formattedResult = document.createElement("span");
  10261. if (!parameters.length)
  10262. return formattedResult;
  10263.  
  10264.  
  10265.  
  10266. for (var i = 0; i < parameters.length; ++i) {
  10267.  
  10268. if (parameters[i] instanceof WebInspector.RemoteObject)
  10269. continue;
  10270.  
  10271. if (typeof parameters[i] === "object")
  10272. parameters[i] = WebInspector.RemoteObject.fromPayload(parameters[i]);
  10273. else
  10274. parameters[i] = WebInspector.RemoteObject.fromPrimitiveValue(parameters[i]);
  10275. }
  10276.  
  10277.  
  10278. var shouldFormatMessage = WebInspector.RemoteObject.type(parameters[0]) === "string" && this.type !== WebInspector.ConsoleMessage.MessageType.Result;
  10279.  
  10280.  
  10281. if (shouldFormatMessage) {
  10282.  
  10283. var result = this._formatWithSubstitutionString(parameters, formattedResult);
  10284. parameters = result.unusedSubstitutions;
  10285. if (parameters.length)
  10286. formattedResult.appendChild(document.createTextNode(" "));
  10287. }
  10288.  
  10289.  
  10290. for (var i = 0; i < parameters.length; ++i) {
  10291.  
  10292. if (shouldFormatMessage && parameters[i].type === "string")
  10293. formattedResult.appendChild(document.createTextNode(parameters[i].description));
  10294. else
  10295. formattedResult.appendChild(this._formatParameter(parameters[i], false, true));
  10296. if (i < parameters.length - 1)
  10297. formattedResult.appendChild(document.createTextNode(" "));
  10298. }
  10299. return formattedResult;
  10300. },
  10301.  
  10302.  
  10303. _formatParameter: function(output, forceObjectFormat, includePreview)
  10304. {
  10305. var type;
  10306. if (forceObjectFormat)
  10307. type = "object";
  10308. else if (output instanceof WebInspector.RemoteObject)
  10309. type = output.subtype || output.type;
  10310. else
  10311. type = typeof output;
  10312.  
  10313. var formatter = this._customFormatters[type];
  10314. if (!formatter) {
  10315. formatter = this._formatParameterAsValue;
  10316. output = output.description;
  10317. }
  10318.  
  10319. var span = document.createElement("span");
  10320. span.className = "console-formatted-" + type + " source-code";
  10321. formatter.call(this, output, span, includePreview);
  10322. return span;
  10323. },
  10324.  
  10325. _formatParameterAsValue: function(val, elem)
  10326. {
  10327. elem.appendChild(document.createTextNode(val));
  10328. },
  10329.  
  10330. _formatParameterAsObject: function(obj, elem, includePreview)
  10331. {
  10332. this._formatParameterAsArrayOrObject(obj, obj.description, elem, includePreview);
  10333. },
  10334.  
  10335.  
  10336. _formatParameterAsArrayOrObject: function(obj, description, elem, includePreview)
  10337. {
  10338. var titleElement = document.createElement("span");
  10339. if (description)
  10340. titleElement.createTextChild(description);
  10341. if (includePreview && obj.preview) {
  10342. titleElement.addStyleClass("console-object-preview");
  10343. var lossless = this._appendObjectPreview(obj, description, titleElement);
  10344. if (lossless) {
  10345. elem.appendChild(titleElement);
  10346. return;
  10347. }
  10348. }
  10349. var section = new WebInspector.ObjectPropertiesSection(obj, titleElement);
  10350. section.enableContextMenu();
  10351. elem.appendChild(section.element);
  10352. },
  10353.  
  10354.  
  10355. _appendObjectPreview: function(obj, description, titleElement)
  10356. {
  10357. var preview = obj.preview;
  10358. var isArray = obj.subtype === "array";
  10359.  
  10360. if (description)
  10361. titleElement.createTextChild(" ");
  10362. titleElement.createTextChild(isArray ? "[" : "{");
  10363. for (var i = 0; i < preview.properties.length; ++i) {
  10364. if (i > 0)
  10365. titleElement.createTextChild(", ");
  10366.  
  10367. var property = preview.properties[i];
  10368. if (!isArray || property.name != i) {
  10369. titleElement.createChild("span", "name").textContent = property.name;
  10370. titleElement.createTextChild(": ");
  10371. }
  10372.  
  10373. this._appendPropertyPreview(titleElement, property);
  10374. }
  10375. if (preview.overflow)
  10376. titleElement.createChild("span").textContent = "\u2026";
  10377. titleElement.createTextChild(isArray ? "]" : "}");
  10378. return preview.lossless;
  10379. },
  10380.  
  10381.  
  10382. _appendPropertyPreview: function(titleElement, property)
  10383. {
  10384. var span = titleElement.createChild("span", "console-formatted-" + property.type);
  10385.  
  10386. if (property.type === "function") {
  10387. span.textContent = "function";
  10388. return;
  10389. }
  10390.  
  10391. if (property.type === "object" && property.subtype === "regexp") {
  10392. span.addStyleClass("console-formatted-string");
  10393. span.textContent = property.value;
  10394. return;
  10395. }
  10396.  
  10397. if (property.type === "object" && property.subtype === "node" && property.value) {
  10398. span.addStyleClass("console-formatted-preview-node");
  10399. WebInspector.DOMPresentationUtils.createSpansForNodeTitle(span, property.value);
  10400. return;
  10401. }
  10402.  
  10403. span.textContent = property.value;
  10404. },
  10405.  
  10406. _formatParameterAsNode: function(object, elem)
  10407. {
  10408. function printNode(nodeId)
  10409. {
  10410. if (!nodeId) {
  10411.  
  10412.  
  10413. this._formatParameterAsObject(object, elem, false);
  10414. return;
  10415. }
  10416. var treeOutline = new WebInspector.ElementsTreeOutline(false, false, true);
  10417. treeOutline.setVisible(true);
  10418. treeOutline.rootDOMNode = WebInspector.domAgent.nodeForId(nodeId);
  10419. treeOutline.element.addStyleClass("outline-disclosure");
  10420. if (!treeOutline.children[0].hasChildren)
  10421. treeOutline.element.addStyleClass("single-node");
  10422. elem.appendChild(treeOutline.element);
  10423. treeOutline.element.treeElementForTest = treeOutline.children[0];
  10424. }
  10425. object.pushNodeToFrontend(printNode.bind(this));
  10426. },
  10427.  
  10428.  
  10429. useArrayPreviewInFormatter: function(array)
  10430. {
  10431. return this.type !== WebInspector.ConsoleMessage.MessageType.DirXML && !!array.preview;
  10432. },
  10433.  
  10434. _formatParameterAsArray: function(array, elem)
  10435. {
  10436. if (this.useArrayPreviewInFormatter(array)) {
  10437. this._formatParameterAsArrayOrObject(array, "", elem, true);
  10438. return;
  10439. }
  10440.  
  10441. const maxFlatArrayLength = 100;
  10442. if (this._isOutdated || array.arrayLength() > maxFlatArrayLength)
  10443. this._formatParameterAsObject(array, elem, false);
  10444. else
  10445. array.getOwnProperties(this._printArray.bind(this, array, elem));
  10446. },
  10447.  
  10448. _formatParameterAsString: function(output, elem)
  10449. {
  10450. var span = document.createElement("span");
  10451. span.className = "console-formatted-string source-code";
  10452. span.appendChild(WebInspector.linkifyStringAsFragment(output.description));
  10453.  
  10454.  
  10455. elem.removeStyleClass("console-formatted-string");
  10456. elem.appendChild(document.createTextNode("\""));
  10457. elem.appendChild(span);
  10458. elem.appendChild(document.createTextNode("\""));
  10459. },
  10460.  
  10461. _printArray: function(array, elem, properties)
  10462. {
  10463. if (!properties)
  10464. return;
  10465.  
  10466. var elements = [];
  10467. for (var i = 0; i < properties.length; ++i) {
  10468. var property = properties[i];
  10469. var name = property.name;
  10470. if (!isNaN(name))
  10471. elements[name] = this._formatAsArrayEntry(property.value);
  10472. }
  10473.  
  10474. elem.appendChild(document.createTextNode("["));
  10475. var lastNonEmptyIndex = -1;
  10476.  
  10477. function appendUndefined(elem, index)
  10478. {
  10479. if (index - lastNonEmptyIndex <= 1)
  10480. return;
  10481. var span = elem.createChild(span, "console-formatted-undefined");
  10482. span.textContent = WebInspector.UIString("undefined ├ù %d", index - lastNonEmptyIndex - 1);
  10483. }
  10484.  
  10485. var length = array.arrayLength();
  10486. for (var i = 0; i < length; ++i) {
  10487. var element = elements[i];
  10488. if (!element)
  10489. continue;
  10490.  
  10491. if (i - lastNonEmptyIndex > 1) {
  10492. appendUndefined(elem, i);
  10493. elem.appendChild(document.createTextNode(", "));
  10494. }
  10495.  
  10496. elem.appendChild(element);
  10497. lastNonEmptyIndex = i;
  10498. if (i < length - 1)
  10499. elem.appendChild(document.createTextNode(", "));
  10500. }
  10501. appendUndefined(elem, length);
  10502.  
  10503. elem.appendChild(document.createTextNode("]"));
  10504. },
  10505.  
  10506. _formatAsArrayEntry: function(output)
  10507. {
  10508.  
  10509. return this._formatParameter(output, output.subtype && output.subtype === "array", false);
  10510. },
  10511.  
  10512. _formatWithSubstitutionString: function(parameters, formattedResult)
  10513. {
  10514. var formatters = {}
  10515.  
  10516. function parameterFormatter(force, obj)
  10517. {
  10518. return this._formatParameter(obj, force, false);
  10519. }
  10520.  
  10521. function stringFormatter(obj)
  10522. {
  10523. return obj.description;
  10524. }
  10525.  
  10526. function floatFormatter(obj)
  10527. {
  10528. if (typeof obj.value !== "number")
  10529. return "NaN";
  10530. return obj.value;
  10531. }
  10532.  
  10533. function integerFormatter(obj)
  10534. {
  10535. if (typeof obj.value !== "number")
  10536. return "NaN";
  10537. return Math.floor(obj.value);
  10538. }
  10539.  
  10540. var currentStyle = null;
  10541. function styleFormatter(obj)
  10542. {
  10543. currentStyle = {};
  10544. var buffer = document.createElement("span");
  10545. buffer.setAttribute("style", obj.description);
  10546. for (var i = 0; i < buffer.style.length; i++) {
  10547. var property = buffer.style[i];
  10548. if (isWhitelistedProperty(property))
  10549. currentStyle[property] = buffer.style[property];
  10550. }
  10551. }
  10552.  
  10553. function isWhitelistedProperty(property)
  10554. {
  10555. var prefixes = ["background", "border", "color", "font", "line", "margin", "padding", "text", "-webkit-background", "-webkit-border", "-webkit-font", "-webkit-margin", "-webkit-padding", "-webkit-text"];
  10556. for (var i = 0; i < prefixes.length; i++) {
  10557. if (property.startsWith(prefixes[i]))
  10558. return true;
  10559. }
  10560. return false;
  10561. }
  10562.  
  10563.  
  10564. formatters.o = parameterFormatter.bind(this, false);
  10565. formatters.s = stringFormatter;
  10566. formatters.f = floatFormatter;
  10567.  
  10568. formatters.i = integerFormatter;
  10569. formatters.d = integerFormatter;
  10570.  
  10571.  
  10572. formatters.c = styleFormatter;
  10573.  
  10574.  
  10575. formatters.O = parameterFormatter.bind(this, true);
  10576.  
  10577. function append(a, b)
  10578. {
  10579. if (b instanceof Node)
  10580. a.appendChild(b);
  10581. else if (b) {
  10582. var toAppend = WebInspector.linkifyStringAsFragment(b.toString());
  10583. if (currentStyle) {
  10584. var wrapper = document.createElement('span');
  10585. for (var key in currentStyle)
  10586. wrapper.style[key] = currentStyle[key];
  10587. wrapper.appendChild(toAppend);
  10588. toAppend = wrapper;
  10589. }
  10590. a.appendChild(toAppend);
  10591. }
  10592. return a;
  10593. }
  10594.  
  10595.  
  10596. return String.format(parameters[0].description, parameters.slice(1), formatters, formattedResult, append);
  10597. },
  10598.  
  10599. clearHighlight: function()
  10600. {
  10601. if (!this._formattedMessage)
  10602. return;
  10603.  
  10604. var highlightedMessage = this._formattedMessage;
  10605. delete this._formattedMessage;
  10606. delete this._anchorElement;
  10607. delete this._messageElement;
  10608. this._formatMessage();
  10609. this._element.replaceChild(this._formattedMessage, highlightedMessage);
  10610. },
  10611.  
  10612. highlightSearchResults: function(regexObject)
  10613. {
  10614. if (!this._formattedMessage)
  10615. return;
  10616.  
  10617. this._highlightSearchResultsInElement(regexObject, this._messageElement);
  10618. if (this._anchorElement)
  10619. this._highlightSearchResultsInElement(regexObject, this._anchorElement);
  10620.  
  10621. this._element.scrollIntoViewIfNeeded();
  10622. },
  10623.  
  10624. _highlightSearchResultsInElement: function(regexObject, element)
  10625. {
  10626. regexObject.lastIndex = 0;
  10627. var text = element.textContent;
  10628. var match = regexObject.exec(text);
  10629. var offset = 0;
  10630. var matchRanges = [];
  10631. while (match) {
  10632. matchRanges.push({ offset: match.index, length: match[0].length });
  10633. match = regexObject.exec(text);
  10634. }
  10635. WebInspector.highlightSearchResults(element, matchRanges);
  10636. },
  10637.  
  10638. matchesRegex: function(regexObject)
  10639. {
  10640. return regexObject.test(this._message) || (this._anchorElement && regexObject.test(this._anchorElement.textContent));
  10641. },
  10642.  
  10643. toMessageElement: function()
  10644. {
  10645. if (this._element)
  10646. return this._element;
  10647.  
  10648. var element = document.createElement("div");
  10649. element.message = this;
  10650. element.className = "console-message";
  10651.  
  10652. this._element = element;
  10653.  
  10654. switch (this.level) {
  10655. case WebInspector.ConsoleMessage.MessageLevel.Tip:
  10656. element.addStyleClass("console-tip-level");
  10657. break;
  10658. case WebInspector.ConsoleMessage.MessageLevel.Log:
  10659. element.addStyleClass("console-log-level");
  10660. break;
  10661. case WebInspector.ConsoleMessage.MessageLevel.Debug:
  10662. element.addStyleClass("console-debug-level");
  10663. break;
  10664. case WebInspector.ConsoleMessage.MessageLevel.Warning:
  10665. element.addStyleClass("console-warning-level");
  10666. break;
  10667. case WebInspector.ConsoleMessage.MessageLevel.Error:
  10668. element.addStyleClass("console-error-level");
  10669. break;
  10670. }
  10671.  
  10672. if (this.type === WebInspector.ConsoleMessage.MessageType.StartGroup || this.type === WebInspector.ConsoleMessage.MessageType.StartGroupCollapsed)
  10673. element.addStyleClass("console-group-title");
  10674.  
  10675. element.appendChild(this.formattedMessage);
  10676.  
  10677. if (this.repeatCount > 1)
  10678. this.updateRepeatCount();
  10679.  
  10680. return element;
  10681. },
  10682.  
  10683. _populateStackTraceTreeElement: function(parentTreeElement)
  10684. {
  10685. for (var i = 0; i < this._stackTrace.length; i++) {
  10686. var frame = this._stackTrace[i];
  10687.  
  10688. var content = document.createElement("div");
  10689. var messageTextElement = document.createElement("span");
  10690. messageTextElement.className = "console-message-text source-code";
  10691. var functionName = frame.functionName || WebInspector.UIString("(anonymous function)");
  10692. messageTextElement.appendChild(document.createTextNode(functionName));
  10693. content.appendChild(messageTextElement);
  10694.  
  10695. if (frame.url) {
  10696. content.appendChild(document.createTextNode(" "));
  10697. var urlElement = this._linkifyCallFrame(frame);
  10698. content.appendChild(urlElement);
  10699. }
  10700.  
  10701. var treeElement = new TreeElement(content);
  10702. parentTreeElement.appendChild(treeElement);
  10703. }
  10704. },
  10705.  
  10706. updateRepeatCount: function() {
  10707. if (!this.repeatCountElement) {
  10708. this.repeatCountElement = document.createElement("span");
  10709. this.repeatCountElement.className = "bubble";
  10710.  
  10711. this._element.insertBefore(this.repeatCountElement, this._element.firstChild);
  10712. this._element.addStyleClass("repeated-message");
  10713. }
  10714. this.repeatCountElement.textContent = this.repeatCount;
  10715. },
  10716.  
  10717. toString: function()
  10718. {
  10719. var sourceString;
  10720. switch (this.source) {
  10721. case WebInspector.ConsoleMessage.MessageSource.HTML:
  10722. sourceString = "HTML";
  10723. break;
  10724. case WebInspector.ConsoleMessage.MessageSource.XML:
  10725. sourceString = "XML";
  10726. break;
  10727. case WebInspector.ConsoleMessage.MessageSource.JS:
  10728. sourceString = "JS";
  10729. break;
  10730. case WebInspector.ConsoleMessage.MessageSource.Network:
  10731. sourceString = "Network";
  10732. break;
  10733. case WebInspector.ConsoleMessage.MessageSource.ConsoleAPI:
  10734. sourceString = "ConsoleAPI";
  10735. break;
  10736. case WebInspector.ConsoleMessage.MessageSource.Other:
  10737. sourceString = "Other";
  10738. break;
  10739. }
  10740.  
  10741. var typeString;
  10742. switch (this.type) {
  10743. case WebInspector.ConsoleMessage.MessageType.Log:
  10744. typeString = "Log";
  10745. break;
  10746. case WebInspector.ConsoleMessage.MessageType.Dir:
  10747. typeString = "Dir";
  10748. break;
  10749. case WebInspector.ConsoleMessage.MessageType.DirXML:
  10750. typeString = "Dir XML";
  10751. break;
  10752. case WebInspector.ConsoleMessage.MessageType.Trace:
  10753. typeString = "Trace";
  10754. break;
  10755. case WebInspector.ConsoleMessage.MessageType.StartGroupCollapsed:
  10756. case WebInspector.ConsoleMessage.MessageType.StartGroup:
  10757. typeString = "Start Group";
  10758. break;
  10759. case WebInspector.ConsoleMessage.MessageType.EndGroup:
  10760. typeString = "End Group";
  10761. break;
  10762. case WebInspector.ConsoleMessage.MessageType.Assert:
  10763. typeString = "Assert";
  10764. break;
  10765. case WebInspector.ConsoleMessage.MessageType.Result:
  10766. typeString = "Result";
  10767. break;
  10768. }
  10769.  
  10770. var levelString;
  10771. switch (this.level) {
  10772. case WebInspector.ConsoleMessage.MessageLevel.Tip:
  10773. levelString = "Tip";
  10774. break;
  10775. case WebInspector.ConsoleMessage.MessageLevel.Log:
  10776. levelString = "Log";
  10777. break;
  10778. case WebInspector.ConsoleMessage.MessageLevel.Warning:
  10779. levelString = "Warning";
  10780. break;
  10781. case WebInspector.ConsoleMessage.MessageLevel.Debug:
  10782. levelString = "Debug";
  10783. break;
  10784. case WebInspector.ConsoleMessage.MessageLevel.Error:
  10785. levelString = "Error";
  10786. break;
  10787. }
  10788.  
  10789. return sourceString + " " + typeString + " " + levelString + ": " + this.formattedMessage.textContent + "\n" + this.url + " line " + this.line;
  10790. },
  10791.  
  10792. get text()
  10793. {
  10794. return this._messageText;
  10795. },
  10796.  
  10797. location: function()
  10798. {
  10799.  
  10800. var lineNumber = this.stackTrace ? this.stackTrace[0].lineNumber - 1 : this.line - 1;
  10801. var columnNumber = this.stackTrace && this.stackTrace[0].columnNumber ? this.stackTrace[0].columnNumber - 1 : 0;
  10802. return WebInspector.debuggerModel.createRawLocationByURL(this.url, lineNumber, columnNumber);
  10803. },
  10804.  
  10805. isEqual: function(msg)
  10806. {
  10807. if (!msg)
  10808. return false;
  10809.  
  10810. if (this._stackTrace) {
  10811. if (!msg._stackTrace)
  10812. return false;
  10813. var l = this._stackTrace;
  10814. var r = msg._stackTrace;
  10815. if (l.length !== r.length) 
  10816. return false;
  10817. for (var i = 0; i < l.length; i++) {
  10818. if (l[i].url !== r[i].url ||
  10819. l[i].functionName !== r[i].functionName ||
  10820. l[i].lineNumber !== r[i].lineNumber ||
  10821. l[i].columnNumber !== r[i].columnNumber)
  10822. return false;
  10823. }
  10824. }
  10825.  
  10826. return (this.source === msg.source)
  10827. && (this.type === msg.type)
  10828. && (this.level === msg.level)
  10829. && (this.line === msg.line)
  10830. && (this.url === msg.url)
  10831. && (this.message === msg.message)
  10832. && (this._request === msg._request);
  10833. },
  10834.  
  10835. get stackTrace()
  10836. {
  10837. return this._stackTrace;
  10838. },
  10839.  
  10840.  
  10841. clone: function()
  10842. {
  10843. return WebInspector.ConsoleMessage.create(this.source, this.level, this._messageText, this.type, this.url, this.line, this.repeatCount, this._parameters, this._stackTrace, this._request ? this._request.requestId : undefined, this._isOutdated);
  10844. },
  10845.  
  10846. __proto__: WebInspector.ConsoleMessage.prototype
  10847. }
  10848.  
  10849.  
  10850.  
  10851.  
  10852.  
  10853.  
  10854. WebInspector.ConsoleView = function(hideContextSelector)
  10855. {
  10856. WebInspector.View.call(this);
  10857.  
  10858. this.element.id = "console-view";
  10859. this.messages = [];
  10860.  
  10861. this._clearConsoleButton = new WebInspector.StatusBarButton(WebInspector.UIString("Clear console log."), "clear-status-bar-item");
  10862. this._clearConsoleButton.addEventListener("click", this._requestClearMessages, this);
  10863.  
  10864. this._frameSelector = new WebInspector.StatusBarComboBox(this._frameChanged.bind(this), "console-context");
  10865. this._contextSelector = new WebInspector.StatusBarComboBox(this._contextChanged.bind(this), "console-context");
  10866.  
  10867. if (hideContextSelector) {
  10868. this._frameSelector.element.addStyleClass("hidden");
  10869. this._contextSelector.element.addStyleClass("hidden");
  10870. }
  10871.  
  10872. this.messagesElement = document.createElement("div");
  10873. this.messagesElement.id = "console-messages";
  10874. this.messagesElement.className = "monospace";
  10875. this.messagesElement.addEventListener("click", this._messagesClicked.bind(this), true);
  10876. this.element.appendChild(this.messagesElement);
  10877. this._scrolledToBottom = true;
  10878.  
  10879. this.promptElement = document.createElement("div");
  10880. this.promptElement.id = "console-prompt";
  10881. this.promptElement.className = "source-code";
  10882. this.promptElement.spellcheck = false;
  10883. this.messagesElement.appendChild(this.promptElement);
  10884. this.messagesElement.appendChild(document.createElement("br"));
  10885.  
  10886. this.topGroup = new WebInspector.ConsoleGroup(null);
  10887. this.messagesElement.insertBefore(this.topGroup.element, this.promptElement);
  10888. this.currentGroup = this.topGroup;
  10889.  
  10890. this._filterBarElement = document.createElement("div");
  10891. this._filterBarElement.className = "scope-bar status-bar-item";
  10892.  
  10893. function createDividerElement()
  10894. {
  10895. var dividerElement = document.createElement("div");
  10896. dividerElement.addStyleClass("scope-bar-divider");
  10897. this._filterBarElement.appendChild(dividerElement);
  10898. }
  10899.  
  10900. var updateFilterHandler = this._updateFilter.bind(this);
  10901.  
  10902. function createFilterElement(category, label)
  10903. {
  10904. var categoryElement = document.createElement("li");
  10905. categoryElement.category = category;
  10906. categoryElement.className = category;
  10907. categoryElement.addEventListener("click", updateFilterHandler, false);
  10908. categoryElement.textContent = label;
  10909.  
  10910. this._filterBarElement.appendChild(categoryElement);
  10911.  
  10912. return categoryElement;
  10913. }
  10914.  
  10915. this.allElement = createFilterElement.call(this, "all", WebInspector.UIString("All"));
  10916. createDividerElement.call(this);
  10917. this.errorElement = createFilterElement.call(this, "errors", WebInspector.UIString("Errors"));
  10918. this.warningElement = createFilterElement.call(this, "warnings", WebInspector.UIString("Warnings"));
  10919. this.logElement = createFilterElement.call(this, "logs", WebInspector.UIString("Logs"));
  10920. this.debugElement = createFilterElement.call(this, "debug", WebInspector.UIString("Debug"));
  10921.  
  10922. this.filter(this.allElement, false);
  10923. this._registerShortcuts();
  10924. this.registerRequiredCSS("textPrompt.css");
  10925.  
  10926. this.messagesElement.addEventListener("contextmenu", this._handleContextMenuEvent.bind(this), false);
  10927.  
  10928. WebInspector.settings.monitoringXHREnabled.addChangeListener(this._monitoringXHREnabledSettingChanged.bind(this));
  10929.  
  10930. WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, this._consoleMessageAdded, this);
  10931. WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.ConsoleCleared, this._consoleCleared, this);
  10932.  
  10933. this._linkifier = new WebInspector.Linkifier();
  10934.  
  10935. this.prompt = new WebInspector.TextPromptWithHistory(WebInspector.runtimeModel.completionsForTextPrompt.bind(WebInspector.runtimeModel));
  10936. this.prompt.setSuggestBoxEnabled("generic-suggest");
  10937. this.prompt.renderAsBlock();
  10938. this.prompt.attach(this.promptElement);
  10939. this.prompt.proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this), false);
  10940. this.prompt.setHistoryData(WebInspector.settings.consoleHistory.get());
  10941.  
  10942. WebInspector.runtimeModel.contextLists().forEach(this._addFrame, this);
  10943. WebInspector.runtimeModel.addEventListener(WebInspector.RuntimeModel.Events.FrameExecutionContextListAdded, this._frameAdded, this);
  10944. WebInspector.runtimeModel.addEventListener(WebInspector.RuntimeModel.Events.FrameExecutionContextListRemoved, this._frameRemoved, this);
  10945. }
  10946.  
  10947. WebInspector.ConsoleView.Events = {
  10948. ConsoleCleared: "console-cleared",
  10949. EntryAdded: "console-entry-added",
  10950. }
  10951.  
  10952. WebInspector.ConsoleView.prototype = {
  10953. get statusBarItems()
  10954. {
  10955. return [this._clearConsoleButton.element, this._frameSelector.element, this._contextSelector.element, this._filterBarElement];
  10956. },
  10957.  
  10958.  
  10959. _frameAdded: function(event)
  10960. {
  10961. var contextList =   (event.data);
  10962. this._addFrame(contextList);
  10963. },
  10964.  
  10965.  
  10966. _addFrame: function(contextList)
  10967. {
  10968. var option = document.createElement("option");
  10969. option.text = contextList.displayName;
  10970. option.title = contextList.url;
  10971. option._contextList = contextList;
  10972. contextList._consoleOption = option;
  10973. this._frameSelector.addOption(option);
  10974. contextList.addEventListener(WebInspector.FrameExecutionContextList.EventTypes.ContextsUpdated, this._frameUpdated, this);
  10975. contextList.addEventListener(WebInspector.FrameExecutionContextList.EventTypes.ContextAdded, this._contextAdded, this);
  10976. this._frameChanged();
  10977. },
  10978.  
  10979.  
  10980. _frameRemoved: function(event)
  10981. {
  10982. var contextList =   (event.data);
  10983. this._frameSelector.removeOption(contextList._consoleOption);
  10984. this._frameChanged();
  10985. },
  10986.  
  10987. _frameChanged: function()
  10988. {
  10989. var context = this._currentFrame();
  10990. if (!context) {
  10991. WebInspector.runtimeModel.setCurrentExecutionContext(null);
  10992. this._contextSelector.element.addStyleClass("hidden");
  10993. return;
  10994. }
  10995.  
  10996. var executionContexts = context.executionContexts();
  10997. if (executionContexts.length)
  10998. WebInspector.runtimeModel.setCurrentExecutionContext(executionContexts[0]);
  10999.  
  11000. if (executionContexts.length === 1) {
  11001. this._contextSelector.element.addStyleClass("hidden");
  11002. return;
  11003. }
  11004. this._contextSelector.element.removeStyleClass("hidden");
  11005. this._contextSelector.removeOptions();
  11006. for (var i = 0; i < executionContexts.length; i++)
  11007. this._appendContextOption(executionContexts[i]);
  11008. },
  11009.  
  11010.  
  11011. _appendContextOption: function(executionContext)
  11012. {
  11013. if (!WebInspector.runtimeModel.currentExecutionContext())
  11014. WebInspector.runtimeModel.setCurrentExecutionContext(executionContext);
  11015. var option = document.createElement("option");
  11016. option.text = executionContext.name;
  11017. option.title = executionContext.id;
  11018. option._executionContext = executionContext;
  11019. this._contextSelector.addOption(option);
  11020. },
  11021.  
  11022.  
  11023. _contextChanged: function(event)
  11024. {
  11025. var option = this._contextSelector.selectedOption();
  11026. WebInspector.runtimeModel.setCurrentExecutionContext(option ? option._executionContext : null);
  11027. },
  11028.  
  11029.  
  11030. _frameUpdated: function(event)
  11031. {
  11032. var contextList =   event.data;
  11033. var option = contextList._consoleOption;
  11034. option.text = contextList.displayName;
  11035. option.title = contextList.url;
  11036. },
  11037.  
  11038.  
  11039. _contextAdded: function(event)
  11040. {
  11041. var contextList =   event.data;
  11042. if (contextList === this._currentFrame())
  11043. this._frameChanged();
  11044. },
  11045.  
  11046.  
  11047. _currentFrame: function()
  11048. {
  11049. var option = this._frameSelector.selectedOption();
  11050. return option ? option._contextList : undefined;
  11051. },
  11052.  
  11053. _updateFilter: function(e)
  11054. {
  11055. var isMac = WebInspector.isMac();
  11056. var selectMultiple = false;
  11057. if (isMac && e.metaKey && !e.ctrlKey && !e.altKey && !e.shiftKey)
  11058. selectMultiple = true;
  11059. if (!isMac && e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey)
  11060. selectMultiple = true;
  11061.  
  11062. this.filter(e.target, selectMultiple);
  11063. },
  11064.  
  11065. filter: function(target, selectMultiple)
  11066. {
  11067. function unselectAll()
  11068. {
  11069. this.allElement.removeStyleClass("selected");
  11070. this.errorElement.removeStyleClass("selected");
  11071. this.warningElement.removeStyleClass("selected");
  11072. this.logElement.removeStyleClass("selected");
  11073. this.debugElement.removeStyleClass("selected");
  11074.  
  11075. this.messagesElement.classList.remove("filter-all", "filter-errors", "filter-warnings", "filter-logs", "filter-debug");
  11076. }
  11077.  
  11078. var targetFilterClass = "filter-" + target.category;
  11079.  
  11080. if (target.category === "all") {
  11081. if (target.hasStyleClass("selected")) {
  11082.  
  11083. return;
  11084. }
  11085.  
  11086. unselectAll.call(this);
  11087. } else {
  11088.  
  11089. if (this.allElement.hasStyleClass("selected")) {
  11090. this.allElement.removeStyleClass("selected");
  11091. this.messagesElement.removeStyleClass("filter-all");
  11092. }
  11093. }
  11094.  
  11095. if (!selectMultiple) {
  11096.  
  11097.  
  11098. unselectAll.call(this);
  11099.  
  11100. target.addStyleClass("selected");
  11101. this.messagesElement.addStyleClass(targetFilterClass);
  11102.  
  11103. return;
  11104. }
  11105.  
  11106. if (target.hasStyleClass("selected")) {
  11107.  
  11108.  
  11109. target.removeStyleClass("selected");
  11110. this.messagesElement.removeStyleClass(targetFilterClass);
  11111. } else {
  11112.  
  11113.  
  11114. target.addStyleClass("selected");
  11115. this.messagesElement.addStyleClass(targetFilterClass);
  11116. }
  11117. },
  11118.  
  11119. willHide: function()
  11120. {
  11121. this.prompt.hideSuggestBox();
  11122. this.prompt.clearAutoComplete(true);
  11123. },
  11124.  
  11125. wasShown: function()
  11126. {
  11127. if (!this.prompt.isCaretInsidePrompt())
  11128. this.prompt.moveCaretToEndOfPrompt();
  11129. },
  11130.  
  11131. afterShow: function()
  11132. {
  11133. WebInspector.setCurrentFocusElement(this.promptElement);
  11134. },
  11135.  
  11136. storeScrollPositions: function()
  11137. {
  11138. WebInspector.View.prototype.storeScrollPositions.call(this);
  11139. this._scrolledToBottom = this.messagesElement.isScrolledToBottom();
  11140. },
  11141.  
  11142. restoreScrollPositions: function()
  11143. {
  11144. if (this._scrolledToBottom)
  11145. this._immediatelyScrollIntoView();
  11146. else
  11147. WebInspector.View.prototype.restoreScrollPositions.call(this);
  11148. },
  11149.  
  11150. onResize: function()
  11151. {
  11152. this.restoreScrollPositions();
  11153. },
  11154.  
  11155. _isScrollIntoViewScheduled: function()
  11156. {
  11157. return !!this._scrollIntoViewTimer;
  11158. },
  11159.  
  11160. _scheduleScrollIntoView: function()
  11161. {
  11162. if (this._scrollIntoViewTimer)
  11163. return;
  11164.  
  11165. function scrollIntoView()
  11166. {
  11167. delete this._scrollIntoViewTimer;
  11168. this.promptElement.scrollIntoView(true);
  11169. }
  11170. this._scrollIntoViewTimer = setTimeout(scrollIntoView.bind(this), 20);
  11171. },
  11172.  
  11173. _immediatelyScrollIntoView: function()
  11174. {
  11175. this.promptElement.scrollIntoView(true);
  11176. this._cancelScheduledScrollIntoView();
  11177. },
  11178.  
  11179. _cancelScheduledScrollIntoView: function()
  11180. {
  11181. if (!this._isScrollIntoViewScheduled())
  11182. return;
  11183.  
  11184. clearTimeout(this._scrollIntoViewTimer);
  11185. delete this._scrollIntoViewTimer;
  11186. },
  11187.  
  11188.  
  11189. _consoleMessageAdded: function(event)
  11190. {
  11191. this._appendConsoleMessage(event.data);
  11192. },
  11193.  
  11194. _appendConsoleMessage: function(msg)
  11195. {
  11196.  
  11197.  
  11198. if (!this._isScrollIntoViewScheduled() && ((msg instanceof WebInspector.ConsoleCommandResult) || this.messagesElement.isScrolledToBottom()))
  11199. this._scheduleScrollIntoView();
  11200.  
  11201. this.messages.push(msg);
  11202.  
  11203. if (msg.type === WebInspector.ConsoleMessage.MessageType.EndGroup) {
  11204. var parentGroup = this.currentGroup.parentGroup
  11205. if (parentGroup)
  11206. this.currentGroup = parentGroup;
  11207. } else {
  11208. if (msg.type === WebInspector.ConsoleMessage.MessageType.StartGroup || msg.type === WebInspector.ConsoleMessage.MessageType.StartGroupCollapsed) {
  11209. var group = new WebInspector.ConsoleGroup(this.currentGroup);
  11210. this.currentGroup.messagesElement.appendChild(group.element);
  11211. this.currentGroup = group;
  11212. }
  11213.  
  11214. this.currentGroup.addMessage(msg);
  11215. }
  11216.  
  11217. this.dispatchEventToListeners(WebInspector.ConsoleView.Events.EntryAdded, msg);
  11218. },
  11219.  
  11220. _consoleCleared: function()
  11221. {
  11222. this._scrolledToBottom = true;
  11223. this.messages = [];
  11224.  
  11225. this.currentGroup = this.topGroup;
  11226. this.topGroup.messagesElement.removeChildren();
  11227.  
  11228. this.dispatchEventToListeners(WebInspector.ConsoleView.Events.ConsoleCleared);
  11229.  
  11230. this._linkifier.reset();
  11231. },
  11232.  
  11233. _handleContextMenuEvent: function(event)
  11234. {
  11235. if (!window.getSelection().isCollapsed) {
  11236.  
  11237.  
  11238. return;
  11239. }
  11240.  
  11241. if (event.target.enclosingNodeOrSelfWithNodeName("a"))
  11242. return;
  11243.  
  11244. var contextMenu = new WebInspector.ContextMenu(event);
  11245.  
  11246. function monitoringXHRItemAction()
  11247. {
  11248. WebInspector.settings.monitoringXHREnabled.set(!WebInspector.settings.monitoringXHREnabled.get());
  11249. }
  11250. contextMenu.appendCheckboxItem(WebInspector.UIString("Log XMLHttpRequests"), monitoringXHRItemAction.bind(this), WebInspector.settings.monitoringXHREnabled.get());
  11251.  
  11252. function preserveLogItemAction()
  11253. {
  11254. WebInspector.settings.preserveConsoleLog.set(!WebInspector.settings.preserveConsoleLog.get());
  11255. }
  11256. contextMenu.appendCheckboxItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Preserve log upon navigation" : "Preserve Log upon Navigation"), preserveLogItemAction.bind(this), WebInspector.settings.preserveConsoleLog.get());
  11257.  
  11258. contextMenu.appendSeparator();
  11259. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Clear console" : "Clear Console"), this._requestClearMessages.bind(this));
  11260. contextMenu.show();
  11261. },
  11262.  
  11263. _monitoringXHREnabledSettingChanged: function(event)
  11264. {
  11265. ConsoleAgent.setMonitoringXHREnabled(event.data);
  11266. },
  11267.  
  11268. _messagesClicked: function(event)
  11269. {
  11270. if (!this.prompt.isCaretInsidePrompt() && window.getSelection().isCollapsed)
  11271. this.prompt.moveCaretToEndOfPrompt();
  11272. },
  11273.  
  11274. _registerShortcuts: function()
  11275. {
  11276. this._shortcuts = {};
  11277.  
  11278. var shortcut = WebInspector.KeyboardShortcut;
  11279. var section = WebInspector.shortcutsScreen.section(WebInspector.UIString("Console"));
  11280.  
  11281. var shortcutL = shortcut.makeDescriptor("l", WebInspector.KeyboardShortcut.Modifiers.Ctrl);
  11282. this._shortcuts[shortcutL.key] = this._requestClearMessages.bind(this);
  11283. var keys = [shortcutL];
  11284. if (WebInspector.isMac()) {
  11285. var shortcutK = shortcut.makeDescriptor("k", WebInspector.KeyboardShortcut.Modifiers.Meta);
  11286. this._shortcuts[shortcutK.key] = this._requestClearMessages.bind(this);
  11287. keys.unshift(shortcutK);
  11288. }
  11289. section.addAlternateKeys(keys, WebInspector.UIString("Clear console"));
  11290.  
  11291. section.addKey(shortcut.makeDescriptor(shortcut.Keys.Tab), WebInspector.UIString("Autocomplete common prefix"));
  11292. section.addKey(shortcut.makeDescriptor(shortcut.Keys.Right), WebInspector.UIString("Accept suggestion"));
  11293.  
  11294. keys = [
  11295. shortcut.makeDescriptor(shortcut.Keys.Down),
  11296. shortcut.makeDescriptor(shortcut.Keys.Up)
  11297. ];
  11298. section.addRelatedKeys(keys, WebInspector.UIString("Next/previous line"));
  11299.  
  11300. if (WebInspector.isMac()) {
  11301. keys = [
  11302. shortcut.makeDescriptor("N", shortcut.Modifiers.Alt),
  11303. shortcut.makeDescriptor("P", shortcut.Modifiers.Alt)
  11304. ];
  11305. section.addRelatedKeys(keys, WebInspector.UIString("Next/previous command"));
  11306. }
  11307.  
  11308. section.addKey(shortcut.makeDescriptor(shortcut.Keys.Enter), WebInspector.UIString("Execute command"));
  11309. },
  11310.  
  11311. _requestClearMessages: function()
  11312. {
  11313. WebInspector.console.requestClearMessages();
  11314. },
  11315.  
  11316. _promptKeyDown: function(event)
  11317. {
  11318. if (isEnterKey(event)) {
  11319. this._enterKeyPressed(event);
  11320. return;
  11321. }
  11322.  
  11323. var shortcut = WebInspector.KeyboardShortcut.makeKeyFromEvent(event);
  11324. var handler = this._shortcuts[shortcut];
  11325. if (handler) {
  11326. handler();
  11327. event.preventDefault();
  11328. return;
  11329. }
  11330. },
  11331.  
  11332. evaluateUsingTextPrompt: function(expression, showResultOnly)
  11333. {
  11334. this._appendCommand(expression, this.prompt.text, false, showResultOnly);
  11335. },
  11336.  
  11337. _enterKeyPressed: function(event)
  11338. {
  11339. if (event.altKey || event.ctrlKey || event.shiftKey)
  11340. return;
  11341.  
  11342. event.consume(true);
  11343.  
  11344. this.prompt.clearAutoComplete(true);
  11345.  
  11346. var str = this.prompt.text;
  11347. if (!str.length)
  11348. return;
  11349. this._appendCommand(str, "", true, false);
  11350. },
  11351.  
  11352. _printResult: function(result, wasThrown, originatingCommand)
  11353. {
  11354. if (!result)
  11355. return;
  11356.  
  11357. this._appendConsoleMessage(new WebInspector.ConsoleCommandResult(result, wasThrown, originatingCommand, this._linkifier));
  11358. },
  11359.  
  11360. _appendCommand: function(text, newPromptText, useCommandLineAPI, showResultOnly)
  11361. {
  11362. if (!showResultOnly) {
  11363. var commandMessage = new WebInspector.ConsoleCommand(text);
  11364. WebInspector.console.interruptRepeatCount();
  11365. this._appendConsoleMessage(commandMessage);
  11366. }
  11367. this.prompt.text = newPromptText;
  11368.  
  11369. function printResult(result, wasThrown)
  11370. {
  11371. if (!result)
  11372. return;
  11373.  
  11374. if (!showResultOnly) {
  11375. this.prompt.pushHistoryItem(text);
  11376. WebInspector.settings.consoleHistory.set(this.prompt.historyData.slice(-30));
  11377. }
  11378.  
  11379. this._printResult(result, wasThrown, commandMessage);
  11380. }
  11381. WebInspector.runtimeModel.evaluate(text, "console", useCommandLineAPI, false, false, true, printResult.bind(this));
  11382.  
  11383. WebInspector.userMetrics.ConsoleEvaluated.record();
  11384. },
  11385.  
  11386. elementsToRestoreScrollPositionsFor: function()
  11387. {
  11388. return [this.messagesElement];
  11389. },
  11390.  
  11391. __proto__: WebInspector.View.prototype
  11392. }
  11393.  
  11394.  
  11395. WebInspector.ConsoleCommand = function(command)
  11396. {
  11397. this.command = command;
  11398. }
  11399.  
  11400. WebInspector.ConsoleCommand.prototype = {
  11401. clearHighlight: function()
  11402. {
  11403. var highlightedMessage = this._formattedCommand;
  11404. delete this._formattedCommand;
  11405. this._formatCommand();
  11406. this._element.replaceChild(this._formattedCommand, highlightedMessage);
  11407. },
  11408.  
  11409. highlightSearchResults: function(regexObject)
  11410. {
  11411. regexObject.lastIndex = 0;
  11412. var text = this.command;
  11413. var match = regexObject.exec(text);
  11414. var offset = 0;
  11415. var matchRanges = [];
  11416. while (match) {
  11417. matchRanges.push({ offset: match.index, length: match[0].length });
  11418. match = regexObject.exec(text);
  11419. }
  11420. WebInspector.highlightSearchResults(this._formattedCommand, matchRanges);
  11421. this._element.scrollIntoViewIfNeeded();
  11422. },
  11423.  
  11424. matchesRegex: function(regexObject)
  11425. {
  11426. return regexObject.test(this.command);
  11427. },
  11428.  
  11429. toMessageElement: function()
  11430. {
  11431. if (!this._element) {
  11432. this._element = document.createElement("div");
  11433. this._element.command = this;
  11434. this._element.className = "console-user-command";
  11435.  
  11436. this._formatCommand();
  11437. this._element.appendChild(this._formattedCommand);
  11438. }
  11439. return this._element;
  11440. },
  11441.  
  11442. _formatCommand: function()
  11443. {
  11444. this._formattedCommand = document.createElement("span");
  11445. this._formattedCommand.className = "console-message-text source-code";
  11446. this._formattedCommand.textContent = this.command;
  11447. },
  11448. }
  11449.  
  11450.  
  11451. WebInspector.ConsoleCommandResult = function(result, wasThrown, originatingCommand, linkifier)
  11452. {
  11453. var level = (wasThrown ? WebInspector.ConsoleMessage.MessageLevel.Error : WebInspector.ConsoleMessage.MessageLevel.Log);
  11454. this.originatingCommand = originatingCommand;
  11455. WebInspector.ConsoleMessageImpl.call(this, WebInspector.ConsoleMessage.MessageSource.JS, level, "", linkifier, WebInspector.ConsoleMessage.MessageType.Result, undefined, undefined, undefined, [result]);
  11456. }
  11457.  
  11458. WebInspector.ConsoleCommandResult.prototype = {
  11459.  
  11460. useArrayPreviewInFormatter: function(array)
  11461. {
  11462. return false;
  11463. },
  11464.  
  11465. toMessageElement: function()
  11466. {
  11467. var element = WebInspector.ConsoleMessageImpl.prototype.toMessageElement.call(this);
  11468. element.addStyleClass("console-user-command-result");
  11469. return element;
  11470. },
  11471.  
  11472. __proto__: WebInspector.ConsoleMessageImpl.prototype
  11473. }
  11474.  
  11475.  
  11476. WebInspector.ConsoleGroup = function(parentGroup)
  11477. {
  11478. this.parentGroup = parentGroup;
  11479.  
  11480. var element = document.createElement("div");
  11481. element.className = "console-group";
  11482. element.group = this;
  11483. this.element = element;
  11484.  
  11485. if (parentGroup) {
  11486. var bracketElement = document.createElement("div");
  11487. bracketElement.className = "console-group-bracket";
  11488. element.appendChild(bracketElement);
  11489. }
  11490.  
  11491. var messagesElement = document.createElement("div");
  11492. messagesElement.className = "console-group-messages";
  11493. element.appendChild(messagesElement);
  11494. this.messagesElement = messagesElement;
  11495. }
  11496.  
  11497. WebInspector.ConsoleGroup.prototype = {
  11498. addMessage: function(msg)
  11499. {
  11500. var element = msg.toMessageElement();
  11501.  
  11502. if (msg.type === WebInspector.ConsoleMessage.MessageType.StartGroup || msg.type === WebInspector.ConsoleMessage.MessageType.StartGroupCollapsed) {
  11503. this.messagesElement.parentNode.insertBefore(element, this.messagesElement);
  11504. element.addEventListener("click", this._titleClicked.bind(this), false);
  11505. var groupElement = element.enclosingNodeOrSelfWithClass("console-group");
  11506. if (groupElement && msg.type === WebInspector.ConsoleMessage.MessageType.StartGroupCollapsed)
  11507. groupElement.addStyleClass("collapsed");
  11508. } else
  11509. this.messagesElement.appendChild(element);
  11510.  
  11511. if (element.previousSibling && msg.originatingCommand && element.previousSibling.command === msg.originatingCommand)
  11512. element.previousSibling.addStyleClass("console-adjacent-user-command-result");
  11513. },
  11514.  
  11515. _titleClicked: function(event)
  11516. {
  11517. var groupTitleElement = event.target.enclosingNodeOrSelfWithClass("console-group-title");
  11518. if (groupTitleElement) {
  11519. var groupElement = groupTitleElement.enclosingNodeOrSelfWithClass("console-group");
  11520. if (groupElement)
  11521. if (groupElement.hasStyleClass("collapsed"))
  11522. groupElement.removeStyleClass("collapsed");
  11523. else
  11524. groupElement.addStyleClass("collapsed");
  11525. groupTitleElement.scrollIntoViewIfNeeded(true);
  11526. }
  11527.  
  11528. event.consume(true);
  11529. }
  11530. }
  11531.  
  11532.  
  11533. WebInspector.consoleView = null;
  11534.  
  11535. WebInspector.ConsoleMessage.create = function(source, level, message, type, url, line, repeatCount, parameters, stackTrace, requestId, isOutdated)
  11536. {
  11537. return new WebInspector.ConsoleMessageImpl(source, level, message, WebInspector.consoleView._linkifier, type, url, line, repeatCount, parameters, stackTrace, requestId, isOutdated);
  11538. }
  11539.  
  11540.  
  11541.  
  11542.  
  11543.  
  11544.  
  11545. WebInspector.Panel = function(name)
  11546. {
  11547. WebInspector.View.call(this);
  11548. WebInspector.panels[name] = this;
  11549.  
  11550. this.element.addStyleClass("panel");
  11551. this.element.addStyleClass(name);
  11552. this._panelName = name;
  11553.  
  11554. this._shortcuts = {};
  11555.  
  11556. WebInspector.settings[this._sidebarWidthSettingName()] = WebInspector.settings.createSetting(this._sidebarWidthSettingName(), undefined);
  11557. }
  11558.  
  11559.  
  11560. WebInspector.Panel.counterRightMargin = 25;
  11561.  
  11562. WebInspector.Panel.prototype = {
  11563. get name()
  11564. {
  11565. return this._panelName;
  11566. },
  11567.  
  11568. show: function()
  11569. {
  11570. WebInspector.View.prototype.show.call(this, WebInspector.inspectorView.panelsElement());
  11571. },
  11572.  
  11573. wasShown: function()
  11574. {
  11575. var statusBarItems = this.statusBarItems;
  11576. if (statusBarItems) {
  11577. this._statusBarItemContainer = document.createElement("div");
  11578. for (var i = 0; i < statusBarItems.length; ++i)
  11579. this._statusBarItemContainer.appendChild(statusBarItems[i]);
  11580. document.getElementById("panel-status-bar").appendChild(this._statusBarItemContainer);
  11581. }
  11582.  
  11583. this.focus();
  11584. },
  11585.  
  11586. willHide: function()
  11587. {
  11588. if (this._statusBarItemContainer && this._statusBarItemContainer.parentNode)
  11589. this._statusBarItemContainer.parentNode.removeChild(this._statusBarItemContainer);
  11590. delete this._statusBarItemContainer;
  11591. },
  11592.  
  11593. reset: function()
  11594. {
  11595. this.searchCanceled();
  11596. },
  11597.  
  11598. defaultFocusedElement: function()
  11599. {
  11600. return this.sidebarTreeElement || this.element;
  11601. },
  11602.  
  11603. searchCanceled: function()
  11604. {
  11605. WebInspector.searchController.updateSearchMatchesCount(0, this);
  11606. },
  11607.  
  11608.  
  11609. performSearch: function(query)
  11610. {
  11611.  
  11612. this.searchCanceled();
  11613. },
  11614.  
  11615. jumpToNextSearchResult: function()
  11616. {
  11617. },
  11618.  
  11619. jumpToPreviousSearchResult: function()
  11620. {
  11621. },
  11622.  
  11623.  
  11624. canSearchAndReplace: function()
  11625. {
  11626. return false;
  11627. },
  11628.  
  11629.  
  11630. replaceSelectionWith: function(text)
  11631. {
  11632. },
  11633.  
  11634.  
  11635. replaceAllWith: function(query, text)
  11636. {
  11637. },
  11638.  
  11639.  
  11640. canFilter: function()
  11641. {
  11642. return false;
  11643. },
  11644.  
  11645.  
  11646. performFilter: function(query)
  11647. {
  11648. },
  11649.  
  11650.  
  11651. createSidebarView: function(parentElement, position, defaultWidth)
  11652. {
  11653. if (this.splitView)
  11654. return;
  11655.  
  11656. if (!parentElement)
  11657. parentElement = this.element;
  11658.  
  11659. this.splitView = new WebInspector.SidebarView(position || WebInspector.SidebarView.SidebarPosition.Left, this._sidebarWidthSettingName(), defaultWidth);
  11660. this.splitView.show(parentElement);
  11661. this.splitView.addEventListener(WebInspector.SidebarView.EventTypes.Resized, this.sidebarResized.bind(this));
  11662.  
  11663. this.sidebarElement = this.splitView.sidebarElement;
  11664. },
  11665.  
  11666.  
  11667. createSidebarViewWithTree: function(parentElement, position, defaultWidth)
  11668. {
  11669. if (this.splitView)
  11670. return;
  11671.  
  11672. this.createSidebarView(parentElement, position);
  11673.  
  11674. this.sidebarTreeElement = document.createElement("ol");
  11675. this.sidebarTreeElement.className = "sidebar-tree";
  11676. this.splitView.sidebarElement.appendChild(this.sidebarTreeElement);
  11677. this.splitView.sidebarElement.addStyleClass("sidebar");
  11678.  
  11679. this.sidebarTree = new TreeOutline(this.sidebarTreeElement);
  11680. this.sidebarTree.panel = this;
  11681. },
  11682.  
  11683. _sidebarWidthSettingName: function()
  11684. {
  11685. return this._panelName + "SidebarWidth";
  11686. },
  11687.  
  11688.  
  11689.  
  11690. get statusBarItems()
  11691. {
  11692. },
  11693.  
  11694. sidebarResized: function(width)
  11695. {
  11696. },
  11697.  
  11698. statusBarResized: function()
  11699. {
  11700. },
  11701.  
  11702.  
  11703. canShowAnchorLocation: function(anchor)
  11704. {
  11705. return false;
  11706. },
  11707.  
  11708.  
  11709. showAnchorLocation: function(anchor)
  11710. {
  11711. },
  11712.  
  11713. elementsToRestoreScrollPositionsFor: function()
  11714. {
  11715. return [];
  11716. },
  11717.  
  11718.  
  11719. handleShortcut: function(event)
  11720. {
  11721. var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(event);
  11722. var handler = this._shortcuts[shortcutKey];
  11723. if (handler) {
  11724. handler(event);
  11725. event.handled = true;
  11726. }
  11727. },
  11728.  
  11729.  
  11730. registerShortcuts: function(keys, handler)
  11731. {
  11732. for (var i = 0; i < keys.length; ++i)
  11733. this._shortcuts[keys[i].key] = handler;
  11734. },
  11735.  
  11736. __proto__: WebInspector.View.prototype
  11737. }
  11738.  
  11739.  
  11740. WebInspector.PanelDescriptor = function(name, title, className, scriptName, panel)
  11741. {
  11742. this._name = name;
  11743. this._title = title;
  11744. this._className = className;
  11745. this._scriptName = scriptName;
  11746. this._panel = panel;
  11747. }
  11748.  
  11749. WebInspector.PanelDescriptor.prototype = {
  11750.  
  11751. name: function()
  11752. {
  11753. return this._name;
  11754. },
  11755.  
  11756.  
  11757. title: function()
  11758. {
  11759. return this._title;
  11760. },
  11761.  
  11762.  
  11763. iconURL: function()
  11764. {
  11765. return this._iconURL;
  11766. },
  11767.  
  11768.  
  11769. setIconURL: function(iconURL)
  11770. {
  11771. this._iconURL = iconURL;
  11772. },
  11773.  
  11774.  
  11775. panel: function()
  11776. {
  11777. if (this._panel)
  11778. return this._panel;
  11779. if (this._scriptName)
  11780. importScript(this._scriptName);
  11781. this._panel = new WebInspector[this._className];
  11782. return this._panel;
  11783. },
  11784.  
  11785. registerShortcuts: function() {}
  11786. }
  11787.  
  11788.  
  11789.  
  11790.  
  11791.  
  11792.  
  11793. WebInspector.InspectorView = function()
  11794. {
  11795. WebInspector.View.call(this);
  11796. this.markAsRoot();
  11797. this.element.id = "main-panels";
  11798. this.element.setAttribute("spellcheck", false);
  11799. this._history = [];
  11800. this._historyIterator = -1;
  11801. document.addEventListener("keydown", this._keyDown.bind(this), false);
  11802. document.addEventListener("keypress", this._keyPress.bind(this), false);
  11803. this._panelOrder = [];
  11804. this._panelDescriptors = {};
  11805.  
  11806.  
  11807. this._openBracketIdentifiers = ["U+005B", "U+00DB"].keySet();
  11808. this._closeBracketIdentifiers = ["U+005D", "U+00DD"].keySet();
  11809. this._footerElementContainer = this.element.createChild("div", "inspector-footer status-bar hidden");
  11810. this._panelsElement = this.element.createChild("div", "fill");
  11811. }
  11812.  
  11813. WebInspector.InspectorView.Events = {
  11814. PanelSelected: "PanelSelected"
  11815. }
  11816.  
  11817. WebInspector.InspectorView.prototype = {
  11818.  
  11819. addPanel: function(panelDescriptor)
  11820. {
  11821. this._panelOrder.push(panelDescriptor.name());
  11822. this._panelDescriptors[panelDescriptor.name()] = panelDescriptor;
  11823. WebInspector.toolbar.addPanel(panelDescriptor);
  11824. },
  11825.  
  11826.  
  11827. panel: function(panelName)
  11828. {
  11829. var panelDescriptor = this._panelDescriptors[panelName];
  11830. if (!panelDescriptor && this._panelOrder.length)
  11831. panelDescriptor = this._panelDescriptors[this._panelOrder[0]];
  11832. return panelDescriptor ? panelDescriptor.panel() : null;
  11833. },
  11834.  
  11835.  
  11836. showPanel: function(panelName)
  11837. {
  11838. var panel = this.panel(panelName);
  11839. if (panel)
  11840. this.setCurrentPanel(panel);
  11841. return panel;
  11842. },
  11843.  
  11844. currentPanel: function()
  11845. {
  11846. return this._currentPanel;
  11847. },
  11848.  
  11849.  
  11850. setCurrentPanel: function(x)
  11851. {
  11852. if (this._currentPanel === x)
  11853. return;
  11854.  
  11855. if (this._currentPanel)
  11856. this._currentPanel.detach();
  11857.  
  11858. this._currentPanel = x;
  11859.  
  11860. if (x) {
  11861. x.show();
  11862. this.dispatchEventToListeners(WebInspector.InspectorView.Events.PanelSelected);
  11863.  
  11864. WebInspector.searchController.cancelSearch();
  11865. }
  11866. for (var panelName in WebInspector.panels) {
  11867. if (WebInspector.panels[panelName] === x) {
  11868. WebInspector.settings.lastActivePanel.set(panelName);
  11869. this._pushToHistory(panelName);
  11870. WebInspector.userMetrics.panelShown(panelName);
  11871. }
  11872. }
  11873. },
  11874.  
  11875. _keyPress: function(event)
  11876. {
  11877.  
  11878.  
  11879. if (event.charCode < 32 && WebInspector.isWin())
  11880. return;
  11881. clearTimeout(this._keyDownTimer);
  11882. delete this._keyDownTimer;
  11883. },
  11884.  
  11885. _keyDown: function(event)
  11886. {
  11887. if (!WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event))
  11888. return;
  11889.  
  11890.  
  11891. if (!event.shiftKey && !event.altKey && event.keyCode > 0x30 && event.keyCode < 0x3A) {
  11892. var panelName = this._panelOrder[event.keyCode - 0x31];
  11893. if (panelName) {
  11894. this.showPanel(panelName);
  11895. event.consume(true);
  11896. }
  11897. return;
  11898. }
  11899.  
  11900.  
  11901.  
  11902.  
  11903. if (!WebInspector.isWin() || (!this._openBracketIdentifiers[event.keyIdentifier] && !this._closeBracketIdentifiers[event.keyIdentifier])) {
  11904. this._keyDownInternal(event);
  11905. return;
  11906. }
  11907.  
  11908. this._keyDownTimer = setTimeout(this._keyDownInternal.bind(this, event), 0);
  11909. },
  11910.  
  11911. _keyDownInternal: function(event)
  11912. {
  11913. if (this._openBracketIdentifiers[event.keyIdentifier]) {
  11914. var isRotateLeft = !event.shiftKey && !event.altKey;
  11915. if (isRotateLeft) {
  11916. var index = this._panelOrder.indexOf(this.currentPanel().name);
  11917. index = (index === 0) ? this._panelOrder.length - 1 : index - 1;
  11918. this.showPanel(this._panelOrder[index]);
  11919. event.consume(true);
  11920. return;
  11921. }
  11922.  
  11923. var isGoBack = event.altKey;
  11924. if (isGoBack && this._canGoBackInHistory()) {
  11925. this._goBackInHistory();
  11926. event.consume(true);
  11927. }
  11928. return;
  11929. }
  11930.  
  11931. if (this._closeBracketIdentifiers[event.keyIdentifier]) {
  11932. var isRotateRight = !event.shiftKey && !event.altKey;
  11933. if (isRotateRight) {
  11934. var index = this._panelOrder.indexOf(this.currentPanel().name);
  11935. index = (index + 1) % this._panelOrder.length;
  11936. this.showPanel(this._panelOrder[index]);
  11937. event.consume(true);
  11938. return;
  11939. }
  11940.  
  11941. var isGoForward = event.altKey;
  11942. if (isGoForward && this._canGoForwardInHistory()) {
  11943. this._goForwardInHistory();
  11944. event.consume(true);
  11945. }
  11946. return;
  11947. }
  11948. },
  11949.  
  11950. _canGoBackInHistory: function()
  11951. {
  11952. return this._historyIterator > 0;
  11953. },
  11954.  
  11955. _goBackInHistory: function()
  11956. {
  11957. this._inHistory = true;
  11958. this.setCurrentPanel(WebInspector.panels[this._history[--this._historyIterator]]);
  11959. delete this._inHistory;
  11960. },
  11961.  
  11962. _canGoForwardInHistory: function()
  11963. {
  11964. return this._historyIterator < this._history.length - 1;
  11965. },
  11966.  
  11967. _goForwardInHistory: function()
  11968. {
  11969. this._inHistory = true;
  11970. this.setCurrentPanel(WebInspector.panels[this._history[++this._historyIterator]]);
  11971. delete this._inHistory;
  11972. },
  11973.  
  11974. _pushToHistory: function(panelName)
  11975. {
  11976. if (this._inHistory)
  11977. return;
  11978.  
  11979. this._history.splice(this._historyIterator + 1, this._history.length - this._historyIterator - 1);
  11980. if (!this._history.length || this._history[this._history.length - 1] !== panelName)
  11981. this._history.push(panelName);
  11982. this._historyIterator = this._history.length - 1;
  11983. },
  11984.  
  11985. panelsElement: function()
  11986. {
  11987. return this._panelsElement;
  11988. },
  11989.  
  11990.  
  11991. setFooterElement: function(element)
  11992. {
  11993. if (element) {
  11994. this._footerElementContainer.removeStyleClass("hidden");
  11995. this._footerElementContainer.appendChild(element);
  11996. this._panelsElement.style.bottom = this._footerElementContainer.offsetHeight + "px";
  11997. } else {
  11998. this._footerElementContainer.addStyleClass("hidden");
  11999. this._footerElementContainer.removeChildren();
  12000. this._panelsElement.style.bottom = 0;
  12001. }
  12002. this.doResize();
  12003. },
  12004.  
  12005.  
  12006. showPanelForAnchorNavigation: function(panel)
  12007. {
  12008. WebInspector.searchController.disableSearchUntilExplicitAction();
  12009. this.setCurrentPanel(panel);
  12010. },
  12011.  
  12012. __proto__: WebInspector.View.prototype
  12013. }
  12014.  
  12015.  
  12016. WebInspector.inspectorView = null;
  12017.  
  12018.  
  12019.  
  12020.  
  12021.  
  12022.  
  12023. WebInspector.AdvancedSearchController = function()
  12024. {
  12025. this._shortcut = WebInspector.AdvancedSearchController.createShortcut();
  12026. this._searchId = 0;
  12027.  
  12028. WebInspector.settings.advancedSearchConfig = WebInspector.settings.createSetting("advancedSearchConfig", new WebInspector.SearchConfig("", true, false));
  12029.  
  12030. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameNavigated, this._frameNavigated, this);
  12031. }
  12032.  
  12033.  
  12034. WebInspector.AdvancedSearchController.createShortcut = function()
  12035. {
  12036. if (WebInspector.isMac())
  12037. return WebInspector.KeyboardShortcut.makeDescriptor("f", WebInspector.KeyboardShortcut.Modifiers.Meta | WebInspector.KeyboardShortcut.Modifiers.Alt);
  12038. else
  12039. return WebInspector.KeyboardShortcut.makeDescriptor("f", WebInspector.KeyboardShortcut.Modifiers.Ctrl | WebInspector.KeyboardShortcut.Modifiers.Shift);
  12040. }
  12041.  
  12042. WebInspector.AdvancedSearchController.prototype = {
  12043.  
  12044. handleShortcut: function(event)
  12045. {
  12046. if (WebInspector.KeyboardShortcut.makeKeyFromEvent(event) === this._shortcut.key) {
  12047. if (!this._searchView || !this._searchView.isShowing() || this._searchView._search !== document.activeElement) {
  12048. WebInspector.showPanel("scripts");
  12049. this.show();
  12050. } else
  12051. this.close();
  12052. event.consume(true);
  12053. return true;
  12054. }
  12055. return false;
  12056. },
  12057.  
  12058. _frameNavigated: function()
  12059. {
  12060. this.resetSearch();
  12061. },
  12062.  
  12063.  
  12064. registerSearchScope: function(searchScope)
  12065. {
  12066.  
  12067. this._searchScope = searchScope;
  12068. },
  12069.  
  12070. show: function()
  12071. {
  12072. if (!this._searchView)
  12073. this._searchView = new WebInspector.SearchView(this);
  12074.  
  12075. this._searchView.syncToSelection();
  12076.  
  12077. if (this._searchView.isShowing())
  12078. this._searchView.focus();
  12079. else
  12080. WebInspector.showViewInDrawer(this._searchView._searchPanelElement, this._searchView, this.stopSearch.bind(this));
  12081. },
  12082.  
  12083. close: function()
  12084. {
  12085. this.stopSearch();
  12086. WebInspector.closeViewInDrawer();
  12087. },
  12088.  
  12089.  
  12090. _onSearchResult: function(searchId, searchResult)
  12091. {
  12092. if (searchId !== this._searchId)
  12093. return;
  12094.  
  12095. this._searchView.addSearchResult(searchResult);
  12096. if (!searchResult.searchMatches.length)
  12097. return;
  12098.  
  12099. if (!this._searchResultsPane) 
  12100. this._searchResultsPane = this._currentSearchScope.createSearchResultsPane(this._searchConfig);        
  12101. this._searchView.resultsPane = this._searchResultsPane; 
  12102. this._searchResultsPane.addSearchResult(searchResult);
  12103. },
  12104.  
  12105.  
  12106. _onSearchFinished: function(searchId, finished)
  12107. {
  12108. if (searchId !== this._searchId)
  12109. return;
  12110.  
  12111. if (!this._searchResultsPane)
  12112. this._searchView.nothingFound();
  12113.  
  12114. this._searchView.searchFinished(finished);
  12115. },
  12116.  
  12117.  
  12118. startSearch: function(searchConfig)
  12119. {
  12120. this.resetSearch();
  12121. ++this._searchId;
  12122.  
  12123. this._searchConfig = searchConfig;
  12124.  
  12125. this._currentSearchScope = this._searchScope;
  12126.  
  12127. var totalSearchResultsCount = this._currentSearchScope.performSearch(searchConfig, this._onSearchResult.bind(this, this._searchId), this._onSearchFinished.bind(this, this._searchId));
  12128. this._searchView.searchStarted(totalSearchResultsCount);
  12129. },
  12130.  
  12131. resetSearch: function()
  12132. {
  12133. this.stopSearch();
  12134.  
  12135. if (this._searchResultsPane) {
  12136. this._searchView.resetResults();
  12137. delete this._searchResultsPane;
  12138. }
  12139. },
  12140.  
  12141. stopSearch: function()
  12142. {
  12143. if (this._currentSearchScope)
  12144. this._currentSearchScope.stopSearch();
  12145. }
  12146. }
  12147.  
  12148.  
  12149. WebInspector.SearchView = function(controller)
  12150. {
  12151. WebInspector.View.call(this);
  12152. this.registerRequiredCSS("textEditor.css");
  12153.  
  12154. this._controller = controller;
  12155.  
  12156. this.element.className = "search-view";
  12157.  
  12158. this._searchPanelElement = document.createElement("span");
  12159. this._searchPanelElement.className = "search-drawer-header";
  12160. this._searchPanelElement.addEventListener("keydown", this._onKeyDown.bind(this), false);
  12161.  
  12162. this._searchResultsElement = this.element.createChild("div");
  12163. this._searchResultsElement.className = "search-results";
  12164.  
  12165. this._searchLabel = this._searchPanelElement.createChild("span");
  12166. this._searchLabel.textContent = WebInspector.UIString("Search sources");
  12167. this._search = this._searchPanelElement.createChild("input");
  12168. this._search.setAttribute("type", "search");
  12169. this._search.addStyleClass("search-config-search");
  12170. this._search.setAttribute("results", "0");
  12171. this._search.setAttribute("size", 30);
  12172.  
  12173. this._ignoreCaseLabel = this._searchPanelElement.createChild("label");
  12174. this._ignoreCaseLabel.addStyleClass("search-config-label");
  12175. this._ignoreCaseCheckbox = this._ignoreCaseLabel.createChild("input");
  12176. this._ignoreCaseCheckbox.setAttribute("type", "checkbox");
  12177. this._ignoreCaseCheckbox.addStyleClass("search-config-checkbox");
  12178. this._ignoreCaseLabel.appendChild(document.createTextNode(WebInspector.UIString("Ignore case")));
  12179.  
  12180. this._regexLabel = this._searchPanelElement.createChild("label");
  12181. this._regexLabel.addStyleClass("search-config-label");
  12182. this._regexCheckbox = this._regexLabel.createChild("input");
  12183. this._regexCheckbox.setAttribute("type", "checkbox");
  12184. this._regexCheckbox.addStyleClass("search-config-checkbox");
  12185. this._regexLabel.appendChild(document.createTextNode(WebInspector.UIString("Regular expression")));
  12186.  
  12187. this._searchStatusBarElement = document.createElement("div");
  12188. this._searchStatusBarElement.className = "search-status-bar-item";
  12189. this._searchMessageElement = this._searchStatusBarElement.createChild("div");
  12190. this._searchMessageElement.className = "search-status-bar-message";
  12191.  
  12192. this._searchResultsMessageElement = document.createElement("span");
  12193. this._searchResultsMessageElement.className = "search-results-status-bar-message";
  12194.  
  12195. this._load();
  12196. }
  12197.  
  12198.  
  12199. WebInspector.SearchView.maxQueriesCount = 20;
  12200.  
  12201. WebInspector.SearchView.prototype = {
  12202.  
  12203. get statusBarItems()
  12204. {
  12205. return [this._searchStatusBarElement, this._searchResultsMessageElement];
  12206. },
  12207.  
  12208.  
  12209. get searchConfig()
  12210. {
  12211. return new WebInspector.SearchConfig(this._search.value, this._ignoreCaseCheckbox.checked, this._regexCheckbox.checked);
  12212. },
  12213.  
  12214. syncToSelection: function()
  12215. {
  12216. var selection = window.getSelection();
  12217. if (selection.rangeCount)
  12218. this._search.value = selection.toString().replace(/\r?\n.*/, "");
  12219. },
  12220.  
  12221.  
  12222. set resultsPane(resultsPane)
  12223. {
  12224. this.resetResults();
  12225. this._searchResultsElement.appendChild(resultsPane.element);
  12226. },
  12227.  
  12228.  
  12229. searchStarted: function(totalSearchResultsCount)
  12230. {
  12231. this.resetResults();
  12232. this._resetCounters();
  12233.  
  12234. this._searchMessageElement.textContent = WebInspector.UIString("Searching...");
  12235. this._progressIndicator = new WebInspector.ProgressIndicator();
  12236. this._progressIndicator.setTotalWork(totalSearchResultsCount);
  12237. this._progressIndicator.show(this._searchStatusBarElement);
  12238.  
  12239. this._updateSearchResultsMessage();
  12240.  
  12241. if (!this._searchingView)
  12242. this._searchingView = new WebInspector.EmptyView(WebInspector.UIString("Searching..."));
  12243. this._searchingView.show(this._searchResultsElement);
  12244. },
  12245.  
  12246. _updateSearchResultsMessage: function()
  12247. {
  12248. if (this._searchMatchesCount && this._searchResultsCount)
  12249. this._searchResultsMessageElement.textContent = WebInspector.UIString("Found %d matches in %d files.", this._searchMatchesCount, this._nonEmptySearchResultsCount);
  12250. else
  12251. this._searchResultsMessageElement.textContent = "";
  12252. },
  12253.  
  12254. resetResults: function()
  12255. {
  12256. if (this._searchingView)
  12257. this._searchingView.detach();
  12258. if (this._notFoundView)
  12259. this._notFoundView.detach();
  12260. this._searchResultsElement.removeChildren();
  12261. },
  12262.  
  12263. _resetCounters: function()
  12264. {
  12265. this._searchMatchesCount = 0;
  12266. this._searchResultsCount = 0;
  12267. this._nonEmptySearchResultsCount = 0;
  12268. },
  12269.  
  12270. nothingFound: function()
  12271. {
  12272. this.resetResults();
  12273.  
  12274. if (!this._notFoundView)
  12275. this._notFoundView = new WebInspector.EmptyView(WebInspector.UIString("No matches found."));
  12276. this._notFoundView.show(this._searchResultsElement);
  12277. this._searchResultsMessageElement.textContent = WebInspector.UIString("No matches found.");
  12278. },
  12279.  
  12280.  
  12281. addSearchResult: function(searchResult)
  12282. {
  12283. this._searchMatchesCount += searchResult.searchMatches.length;
  12284. this._searchResultsCount++;
  12285. if (searchResult.searchMatches.length)
  12286. this._nonEmptySearchResultsCount++;
  12287. this._updateSearchResultsMessage();
  12288. if (this._progressIndicator.isCanceled())
  12289. this._onCancel();
  12290. else
  12291. this._progressIndicator.setWorked(this._searchResultsCount);
  12292. },
  12293.  
  12294.  
  12295. searchFinished: function(finished)
  12296. {
  12297. this._progressIndicator.done();
  12298. this._searchMessageElement.textContent = finished ? WebInspector.UIString("Search finished.") : WebInspector.UIString("Search interrupted.");
  12299. },
  12300.  
  12301. focus: function()
  12302. {
  12303. WebInspector.setCurrentFocusElement(this._search);
  12304. this._search.select();
  12305. },
  12306.  
  12307. wasShown: function()
  12308. {
  12309. this.focus();
  12310. },
  12311.  
  12312. willHide: function()
  12313. {
  12314. this._controller.stopSearch();
  12315. },
  12316.  
  12317.  
  12318. _onKeyDown: function(event)
  12319. {
  12320. switch (event.keyCode) {
  12321. case WebInspector.KeyboardShortcut.Keys.Enter.code:
  12322. this._onAction();
  12323. break;
  12324. case WebInspector.KeyboardShortcut.Keys.Esc.code:
  12325. this._controller.close();
  12326. event.consume(true);
  12327. break;
  12328. }        
  12329. },
  12330.  
  12331. _save: function()
  12332. {
  12333. var searchConfig = new WebInspector.SearchConfig(this.searchConfig.query, this.searchConfig.ignoreCase, this.searchConfig.isRegex); 
  12334. WebInspector.settings.advancedSearchConfig.set(searchConfig);
  12335. },
  12336.  
  12337. _load: function()
  12338. {
  12339. var searchConfig = WebInspector.settings.advancedSearchConfig.get();
  12340. this._search.value = searchConfig.query;
  12341. this._ignoreCaseCheckbox.checked = searchConfig.ignoreCase;
  12342. this._regexCheckbox.checked = searchConfig.isRegex;
  12343. },
  12344.  
  12345. _onCancel: function()
  12346. {
  12347. this._controller.stopSearch();
  12348. this.focus();
  12349. },
  12350.  
  12351. _onAction: function()
  12352. {
  12353. if (!this.searchConfig.query || !this.searchConfig.query.length)
  12354. return;
  12355.  
  12356. this._save();
  12357. this._controller.startSearch(this.searchConfig);
  12358. },
  12359.  
  12360. __proto__: WebInspector.View.prototype
  12361. }
  12362.  
  12363.  
  12364.  
  12365. WebInspector.SearchConfig = function(query, ignoreCase, isRegex)
  12366. {
  12367. this.query = query;
  12368. this.ignoreCase = ignoreCase;
  12369. this.isRegex = isRegex;
  12370. }
  12371.  
  12372.  
  12373. WebInspector.SearchScope = function()
  12374. {
  12375. }
  12376.  
  12377. WebInspector.SearchScope.prototype = {
  12378.  
  12379. performSearch: function(searchConfig, searchResultCallback, searchFinishedCallback) { },
  12380.  
  12381. stopSearch: function() { },
  12382.  
  12383.  
  12384. createSearchResultsPane: function(searchConfig) { }
  12385. }
  12386.  
  12387.  
  12388. WebInspector.SearchResult = function(offset, length)
  12389. {
  12390. this.offset = offset;
  12391. this.length = length;    
  12392. }
  12393.  
  12394.  
  12395. WebInspector.SearchResultsPane = function(searchConfig)
  12396. {
  12397. this._searchConfig = searchConfig;
  12398. this.element = document.createElement("div");
  12399. }
  12400.  
  12401. WebInspector.SearchResultsPane.prototype = {
  12402.  
  12403. get searchConfig()
  12404. {
  12405. return this._searchConfig;
  12406. },
  12407.  
  12408.  
  12409. addSearchResult: function(searchResult) { }
  12410. }
  12411.  
  12412.  
  12413. WebInspector.FileBasedSearchResultsPane = function(searchConfig)
  12414. {
  12415. WebInspector.SearchResultsPane.call(this, searchConfig);
  12416.  
  12417. this._searchResults = [];
  12418.  
  12419. this.element.id ="search-results-pane-file-based";
  12420.  
  12421. this._treeOutlineElement = document.createElement("ol");
  12422. this._treeOutlineElement.className = "search-results-outline-disclosure";
  12423. this.element.appendChild(this._treeOutlineElement);
  12424. this._treeOutline = new TreeOutline(this._treeOutlineElement);
  12425.  
  12426. this._matchesExpandedCount = 0;
  12427. }
  12428.  
  12429. WebInspector.FileBasedSearchResultsPane.matchesExpandedByDefaultCount = 20;
  12430. WebInspector.FileBasedSearchResultsPane.fileMatchesShownAtOnce = 20;
  12431.  
  12432. WebInspector.FileBasedSearchResultsPane.prototype = {
  12433.  
  12434. _createAnchor: function(uiSourceCode, lineNumber, columnNumber)
  12435. {
  12436. var anchor = document.createElement("a");
  12437. anchor.preferredPanel = "scripts";
  12438. anchor.href = sanitizeHref(uiSourceCode.url);
  12439. anchor.uiSourceCode = uiSourceCode;
  12440. anchor.lineNumber = lineNumber;
  12441. return anchor;
  12442. },
  12443.  
  12444.  
  12445. addSearchResult: function(searchResult)
  12446. {
  12447. this._searchResults.push(searchResult);
  12448. var uiSourceCode = searchResult.uiSourceCode;
  12449. var searchMatches = searchResult.searchMatches;
  12450.  
  12451. var fileTreeElement = this._addFileTreeElement(uiSourceCode.url, searchMatches.length, this._searchResults.length - 1);
  12452. },
  12453.  
  12454.  
  12455. _fileTreeElementExpanded: function(searchResult, fileTreeElement)
  12456. {
  12457. if (fileTreeElement._initialized)
  12458. return;
  12459.  
  12460. var toIndex = Math.min(searchResult.searchMatches.length, WebInspector.FileBasedSearchResultsPane.fileMatchesShownAtOnce);
  12461. if (toIndex < searchResult.searchMatches.length) {
  12462. this._appendSearchMatches(fileTreeElement, searchResult, 0, toIndex - 1);
  12463. this._appendShowMoreMatchesElement(fileTreeElement, searchResult, toIndex - 1);
  12464. } else
  12465. this._appendSearchMatches(fileTreeElement, searchResult, 0, toIndex);
  12466.  
  12467. fileTreeElement._initialized = true;
  12468. },
  12469.  
  12470.  
  12471. _appendSearchMatches: function(fileTreeElement, searchResult, fromIndex, toIndex)
  12472. {
  12473. var uiSourceCode = searchResult.uiSourceCode;
  12474. var searchMatches = searchResult.searchMatches;
  12475.  
  12476. var regex = createSearchRegex(this._searchConfig.query, !this._searchConfig.ignoreCase, this._searchConfig.isRegex);
  12477. for (var i = fromIndex; i < toIndex; ++i) {
  12478. var lineNumber = searchMatches[i].lineNumber;
  12479. var lineContent = searchMatches[i].lineContent;
  12480. var matchRanges = this._regexMatchRanges(lineContent, regex);
  12481.  
  12482. var anchor = this._createAnchor(uiSourceCode, lineNumber, matchRanges[0].offset);
  12483.  
  12484. var numberString = numberToStringWithSpacesPadding(lineNumber + 1, 4);
  12485. var lineNumberSpan = document.createElement("span");
  12486. lineNumberSpan.addStyleClass("webkit-line-number");
  12487. lineNumberSpan.addStyleClass("search-match-line-number");
  12488. lineNumberSpan.textContent = numberString;
  12489. anchor.appendChild(lineNumberSpan);
  12490.  
  12491. var contentSpan = this._createContentSpan(lineContent, matchRanges);
  12492. anchor.appendChild(contentSpan);
  12493.  
  12494. var searchMatchElement = new TreeElement("", null, false);
  12495. fileTreeElement.appendChild(searchMatchElement);
  12496. searchMatchElement.listItemElement.className = "search-match source-code";
  12497. searchMatchElement.listItemElement.appendChild(anchor);
  12498. }
  12499. },
  12500.  
  12501.  
  12502. _appendShowMoreMatchesElement: function(fileTreeElement, searchResult, startMatchIndex)
  12503. {
  12504. var matchesLeftCount = searchResult.searchMatches.length - startMatchIndex;
  12505. var showMoreMatchesText = WebInspector.UIString("Show all matches (%d more).", matchesLeftCount);
  12506. var showMoreMatchesElement = new TreeElement(showMoreMatchesText, null, false);
  12507. fileTreeElement.appendChild(showMoreMatchesElement);
  12508. showMoreMatchesElement.listItemElement.addStyleClass("show-more-matches");
  12509. showMoreMatchesElement.onselect = this._showMoreMatchesElementSelected.bind(this, searchResult, startMatchIndex, showMoreMatchesElement);
  12510. },
  12511.  
  12512.  
  12513. _showMoreMatchesElementSelected: function(searchResult, startMatchIndex, showMoreMatchesElement)
  12514. {
  12515. var fileTreeElement = showMoreMatchesElement.parent;
  12516. fileTreeElement.removeChild(showMoreMatchesElement);
  12517. this._appendSearchMatches(fileTreeElement, searchResult, startMatchIndex, searchResult.searchMatches.length);
  12518. },
  12519.  
  12520.  
  12521. _addFileTreeElement: function(fileName, searchMatchesCount, searchResultIndex)
  12522. {
  12523. var fileTreeElement = new TreeElement("", null, true);
  12524. fileTreeElement.toggleOnClick = true;
  12525. fileTreeElement.selectable = false;
  12526.  
  12527. this._treeOutline.appendChild(fileTreeElement);
  12528. fileTreeElement.listItemElement.addStyleClass("search-result");
  12529.  
  12530. var fileNameSpan = document.createElement("span");
  12531. fileNameSpan.className = "search-result-file-name";
  12532. fileNameSpan.textContent = fileName;
  12533. fileTreeElement.listItemElement.appendChild(fileNameSpan);
  12534.  
  12535. var matchesCountSpan = document.createElement("span");
  12536. matchesCountSpan.className = "search-result-matches-count";
  12537. if (searchMatchesCount === 1)
  12538. matchesCountSpan.textContent = WebInspector.UIString("(%d match)", searchMatchesCount);
  12539. else
  12540. matchesCountSpan.textContent = WebInspector.UIString("(%d matches)", searchMatchesCount);
  12541.  
  12542. fileTreeElement.listItemElement.appendChild(matchesCountSpan);
  12543.  
  12544. var searchResult = this._searchResults[searchResultIndex];
  12545. fileTreeElement.onexpand = this._fileTreeElementExpanded.bind(this, searchResult, fileTreeElement);
  12546.  
  12547.  
  12548. if (this._matchesExpandedCount < WebInspector.FileBasedSearchResultsPane.matchesExpandedByDefaultCount)
  12549. fileTreeElement.expand();
  12550. this._matchesExpandedCount += searchResult.searchMatches.length;
  12551.  
  12552. return fileTreeElement; 
  12553. },
  12554.  
  12555.  
  12556. _regexMatchRanges: function(lineContent, regex)
  12557. {
  12558. regex.lastIndex = 0;
  12559. var match;
  12560. var offset = 0;
  12561. var matchRanges = [];
  12562. while ((regex.lastIndex < lineContent.length) && (match = regex.exec(lineContent)))
  12563. matchRanges.push(new WebInspector.SearchResult(match.index, match[0].length));
  12564.  
  12565. return matchRanges;
  12566. },
  12567.  
  12568.  
  12569. _createContentSpan: function(lineContent, matchRanges)
  12570. {
  12571. var contentSpan = document.createElement("span");
  12572. contentSpan.className = "search-match-content";
  12573. contentSpan.textContent = lineContent;
  12574. WebInspector.highlightRangesWithStyleClass(contentSpan, matchRanges, "highlighted-match");
  12575. return contentSpan;
  12576. },
  12577.  
  12578. __proto__: WebInspector.SearchResultsPane.prototype
  12579. }
  12580.  
  12581.  
  12582. WebInspector.FileBasedSearchResultsPane.SearchResult = function(uiSourceCode, searchMatches) {
  12583. this.uiSourceCode = uiSourceCode;
  12584. this.searchMatches = searchMatches;
  12585. }
  12586.  
  12587.  
  12588. WebInspector.advancedSearchController = null;
  12589.  
  12590.  
  12591.  
  12592.  
  12593.  
  12594.  
  12595. WebInspector.TimelineGrid = function()
  12596. {
  12597. this.element = document.createElement("div");
  12598.  
  12599. this._itemsGraphsElement = document.createElement("div");
  12600. this._itemsGraphsElement.id = "resources-graphs";
  12601. this.element.appendChild(this._itemsGraphsElement);
  12602.  
  12603. this._dividersElement = document.createElement("div");
  12604. this._dividersElement.className = "resources-dividers";
  12605. this.element.appendChild(this._dividersElement);
  12606.  
  12607. this._gridHeaderElement = document.createElement("div"); 
  12608.  
  12609. this._eventDividersElement = document.createElement("div");
  12610. this._eventDividersElement.className = "resources-event-dividers";
  12611. this._gridHeaderElement.appendChild(this._eventDividersElement);
  12612.  
  12613. this._dividersLabelBarElement = document.createElement("div");
  12614. this._dividersLabelBarElement.className = "resources-dividers-label-bar";
  12615. this._gridHeaderElement.appendChild(this._dividersLabelBarElement);
  12616.  
  12617. this.element.appendChild(this._gridHeaderElement);
  12618. }
  12619.  
  12620. WebInspector.TimelineGrid.prototype = {
  12621. get itemsGraphsElement()
  12622. {
  12623. return this._itemsGraphsElement;
  12624. },
  12625.  
  12626. get dividersElement()
  12627. {
  12628. return this._dividersElement;
  12629. },
  12630.  
  12631. get dividersLabelBarElement()
  12632. {
  12633. return this._dividersLabelBarElement;
  12634. },
  12635.  
  12636. get gridHeaderElement()
  12637. {
  12638. return this._gridHeaderElement;
  12639. },
  12640.  
  12641. removeDividers: function()
  12642. {
  12643. this._dividersElement.removeChildren();
  12644. this._dividersLabelBarElement.removeChildren();
  12645. },
  12646.  
  12647. updateDividers: function(calculator)
  12648. {
  12649. var dividersElementClientWidth = this._dividersElement.clientWidth;
  12650. var dividerCount = Math.round(dividersElementClientWidth / 64);
  12651. var slice = calculator.boundarySpan() / dividerCount;
  12652.  
  12653. this._currentDividerSlice = slice;
  12654.  
  12655.  
  12656. var divider = this._dividersElement.firstChild;
  12657. var dividerLabelBar = this._dividersLabelBarElement.firstChild;
  12658.  
  12659. var paddingLeft = calculator.paddingLeft;
  12660. for (var i = paddingLeft ? 0 : 1; i <= dividerCount; ++i) {
  12661. if (!divider) {
  12662. divider = document.createElement("div");
  12663. divider.className = "resources-divider";
  12664. this._dividersElement.appendChild(divider);
  12665.  
  12666. dividerLabelBar = document.createElement("div");
  12667. dividerLabelBar.className = "resources-divider";
  12668. var label = document.createElement("div");
  12669. label.className = "resources-divider-label";
  12670. dividerLabelBar._labelElement = label;
  12671. dividerLabelBar.appendChild(label);
  12672. this._dividersLabelBarElement.appendChild(dividerLabelBar);
  12673. }
  12674.  
  12675. if (i === (paddingLeft ? 0 : 1)) {
  12676. divider.addStyleClass("first");
  12677. dividerLabelBar.addStyleClass("first");
  12678. } else {
  12679. divider.removeStyleClass("first");
  12680. dividerLabelBar.removeStyleClass("first");
  12681. }
  12682.  
  12683. if (i === dividerCount) {
  12684. divider.addStyleClass("last");
  12685. dividerLabelBar.addStyleClass("last");
  12686. } else {
  12687. divider.removeStyleClass("last");
  12688. dividerLabelBar.removeStyleClass("last");
  12689. }
  12690.  
  12691. var left;
  12692. if (!slice) {
  12693. left = dividersElementClientWidth / dividerCount * i + paddingLeft;
  12694. dividerLabelBar._labelElement.textContent = "";
  12695. } else {
  12696. left = calculator.computePosition(calculator.minimumBoundary() + slice * i);
  12697. dividerLabelBar._labelElement.textContent = calculator.formatTime(slice * i);
  12698. }
  12699. var percentLeft = 100 * left / dividersElementClientWidth;
  12700. this._setDividerAndBarLeft(divider, dividerLabelBar, percentLeft);
  12701.  
  12702. divider = divider.nextSibling;
  12703. dividerLabelBar = dividerLabelBar.nextSibling;
  12704. }
  12705.  
  12706.  
  12707. while (divider) {
  12708. var nextDivider = divider.nextSibling;
  12709. this._dividersElement.removeChild(divider);
  12710. divider = nextDivider;
  12711. }
  12712. while (dividerLabelBar) {
  12713. var nextDivider = dividerLabelBar.nextSibling;
  12714. this._dividersLabelBarElement.removeChild(dividerLabelBar);
  12715. dividerLabelBar = nextDivider;
  12716. }
  12717. return true;
  12718. },
  12719.  
  12720. _setDividerAndBarLeft: function(divider, dividerLabelBar, percentLeft)
  12721. {
  12722. var percentStyleLeft = parseFloat(divider.style.left);
  12723. if (!isNaN(percentStyleLeft) && Math.abs(percentStyleLeft - percentLeft) < 0.1)
  12724. return;
  12725. divider.style.left = percentLeft + "%";
  12726. dividerLabelBar.style.left = percentLeft + "%";
  12727. },
  12728.  
  12729. addEventDivider: function(divider)
  12730. {
  12731. this._eventDividersElement.appendChild(divider);
  12732. },
  12733.  
  12734. addEventDividers: function(dividers)
  12735. {
  12736. this._gridHeaderElement.removeChild(this._eventDividersElement);
  12737. for (var i = 0; i < dividers.length; ++i) {
  12738. if (dividers[i])
  12739. this._eventDividersElement.appendChild(dividers[i]);
  12740. }
  12741. this._gridHeaderElement.appendChild(this._eventDividersElement);
  12742. },
  12743.  
  12744. removeEventDividers: function()
  12745. {
  12746. this._eventDividersElement.removeChildren();
  12747. },
  12748.  
  12749. hideEventDividers: function()
  12750. {
  12751. this._eventDividersElement.addStyleClass("hidden");
  12752. },
  12753.  
  12754. showEventDividers: function()
  12755. {
  12756. this._eventDividersElement.removeStyleClass("hidden");
  12757. },
  12758.  
  12759. setScrollAndDividerTop: function(scrollTop, dividersTop)
  12760. {
  12761. this._dividersElement.style.top = scrollTop + "px";
  12762. }
  12763. }
  12764.  
  12765.  
  12766. WebInspector.TimelineGrid.Calculator = function() { }
  12767.  
  12768. WebInspector.TimelineGrid.Calculator.prototype = {
  12769.  
  12770. computePosition: function(time) { },
  12771.  
  12772.  
  12773. formatTime: function(time) { },
  12774.  
  12775.  
  12776. minimumBoundary: function() { },
  12777.  
  12778.  
  12779. maximumBoundary: function() { },
  12780.  
  12781.  
  12782. boundarySpan: function() { }
  12783. }
  12784.  
  12785.  
  12786.  
  12787.  
  12788.  
  12789.  
  12790. WebInspector.ContentProvider = function() { }
  12791.  
  12792. WebInspector.ContentProvider.prototype = {
  12793.  
  12794. contentURL: function() { },
  12795.  
  12796.  
  12797. contentType: function() { },
  12798.  
  12799.  
  12800. requestContent: function(callback) { },
  12801.  
  12802.  
  12803. searchInContent: function(query, caseSensitive, isRegex, callback) { }
  12804. }
  12805.  
  12806.  
  12807. WebInspector.ContentProvider.SearchMatch = function(lineNumber, lineContent) {
  12808. this.lineNumber = lineNumber;
  12809. this.lineContent = lineContent;
  12810. }
  12811.  
  12812.  
  12813.  
  12814.  
  12815.  
  12816.  
  12817. WebInspector.Resource = function(request, url, documentURL, frameId, loaderId, type, mimeType, isHidden)
  12818. {
  12819. this._request = request;
  12820. this.url = url;
  12821. this._documentURL = documentURL;
  12822. this._frameId = frameId;
  12823. this._loaderId = loaderId;
  12824. this._type = type || WebInspector.resourceTypes.Other;
  12825. this._mimeType = mimeType;
  12826. this._isHidden = isHidden;
  12827.  
  12828. this._content;
  12829. this._contentEncoded;
  12830. this._pendingContentCallbacks = [];
  12831. if (this._request && !this._request.finished)
  12832. this._request.addEventListener(WebInspector.NetworkRequest.Events.FinishedLoading, this._requestFinished, this);
  12833. }
  12834.  
  12835. WebInspector.Resource.Events = {
  12836. MessageAdded: "message-added",
  12837. MessagesCleared: "messages-cleared",
  12838. }
  12839.  
  12840. WebInspector.Resource.prototype = {
  12841.  
  12842. get request()
  12843. {
  12844. return this._request;
  12845. },
  12846.  
  12847.  
  12848. get url()
  12849. {
  12850. return this._url;
  12851. },
  12852.  
  12853. set url(x)
  12854. {
  12855. this._url = x;
  12856. this._parsedURL = new WebInspector.ParsedURL(x);
  12857. },
  12858.  
  12859. get parsedURL()
  12860. {
  12861. return this._parsedURL;
  12862. },
  12863.  
  12864.  
  12865. get documentURL()
  12866. {
  12867. return this._documentURL;
  12868. },
  12869.  
  12870.  
  12871. get frameId()
  12872. {
  12873. return this._frameId;
  12874. },
  12875.  
  12876.  
  12877. get loaderId()
  12878. {
  12879. return this._loaderId;
  12880. },
  12881.  
  12882.  
  12883. get displayName()
  12884. {
  12885. return this._parsedURL.displayName;
  12886. },
  12887.  
  12888.  
  12889. get type()
  12890. {
  12891. return this._request ? this._request.type : this._type;
  12892. },
  12893.  
  12894.  
  12895. get mimeType()
  12896. {
  12897. return this._request ? this._request.mimeType : this._mimeType;
  12898. },
  12899.  
  12900.  
  12901. get messages()
  12902. {
  12903. return this._messages || [];
  12904. },
  12905.  
  12906.  
  12907. addMessage: function(msg)
  12908. {
  12909. if (!msg.isErrorOrWarning() || !msg.message)
  12910. return;
  12911.  
  12912. if (!this._messages)
  12913. this._messages = [];
  12914. this._messages.push(msg);
  12915. this.dispatchEventToListeners(WebInspector.Resource.Events.MessageAdded, msg);
  12916. },
  12917.  
  12918.  
  12919. get errors()
  12920. {
  12921. return this._errors || 0;
  12922. },
  12923.  
  12924. set errors(x)
  12925. {
  12926. this._errors = x;
  12927. },
  12928.  
  12929.  
  12930. get warnings()
  12931. {
  12932. return this._warnings || 0;
  12933. },
  12934.  
  12935. set warnings(x)
  12936. {
  12937. this._warnings = x;
  12938. },
  12939.  
  12940. clearErrorsAndWarnings: function()
  12941. {
  12942. this._messages = [];
  12943. this._warnings = 0;
  12944. this._errors = 0;
  12945. this.dispatchEventToListeners(WebInspector.Resource.Events.MessagesCleared);
  12946. },
  12947.  
  12948.  
  12949. get content()
  12950. {
  12951. return this._content;
  12952. },
  12953.  
  12954.  
  12955. get contentEncoded()
  12956. {
  12957. return this._contentEncoded;
  12958. },
  12959.  
  12960.  
  12961. contentURL: function()
  12962. {
  12963. return this._url;
  12964. },
  12965.  
  12966.  
  12967. contentType: function()
  12968. {
  12969. return this.type;
  12970. },
  12971.  
  12972.  
  12973. requestContent: function(callback)
  12974. {
  12975. if (typeof this._content !== "undefined") {
  12976. callback(this._content, !!this._contentEncoded, this.canonicalMimeType());
  12977. return;
  12978. }
  12979.  
  12980. this._pendingContentCallbacks.push(callback);
  12981. if (!this._request || this._request.finished)
  12982. this._innerRequestContent();
  12983. },
  12984.  
  12985. canonicalMimeType: function()
  12986. {
  12987. return this.type.canonicalMimeType() || this.mimeType;
  12988. },
  12989.  
  12990.  
  12991. searchInContent: function(query, caseSensitive, isRegex, callback)
  12992. {
  12993.  
  12994. function callbackWrapper(error, searchMatches)
  12995. {
  12996. callback(searchMatches || []);
  12997. }
  12998.  
  12999. if (this.frameId)
  13000. PageAgent.searchInResource(this.frameId, this.url, query, caseSensitive, isRegex, callbackWrapper);
  13001. else
  13002. callback([]);
  13003. },
  13004.  
  13005.  
  13006. populateImageSource: function(image)
  13007. {
  13008. function onResourceContent()
  13009. {
  13010. var imageSrc = WebInspector.contentAsDataURL(this._content, this.mimeType, this._contentEncoded);
  13011. if (imageSrc === null)
  13012. imageSrc = this.url;
  13013. image.src = imageSrc;
  13014. }
  13015.  
  13016. this.requestContent(onResourceContent.bind(this));
  13017. },
  13018.  
  13019. _requestFinished: function()
  13020. {
  13021. this._request.removeEventListener(WebInspector.NetworkRequest.Events.FinishedLoading, this._requestFinished, this);
  13022. if (this._pendingContentCallbacks.length)
  13023. this._innerRequestContent();
  13024. },
  13025.  
  13026.  
  13027. _innerRequestContent: function()
  13028. {
  13029. if (this._contentRequested)
  13030. return;
  13031. this._contentRequested = true;
  13032.  
  13033.  
  13034. function contentLoaded(content, contentEncoded)
  13035. {
  13036. this._content = content;
  13037. this._contentEncoded = contentEncoded;
  13038. var callbacks = this._pendingContentCallbacks.slice();
  13039. for (var i = 0; i < callbacks.length; ++i)
  13040. callbacks[i](this._content, this._contentEncoded, this.canonicalMimeType());
  13041. this._pendingContentCallbacks.length = 0;
  13042. delete this._contentRequested;
  13043. }
  13044.  
  13045.  
  13046. function resourceContentLoaded(error, content, contentEncoded)
  13047. {
  13048. if (error)
  13049. console.error("Resource content request failed: " + error);
  13050. contentLoaded.call(this, error ? null : content, contentEncoded);
  13051. }
  13052.  
  13053. if (this.request) {
  13054.  
  13055. function requestContentLoaded(content, contentEncoded, mimeType)
  13056. {
  13057. contentLoaded.call(this, content, contentEncoded);
  13058. }
  13059.  
  13060. this.request.requestContent(requestContentLoaded.bind(this));
  13061. return;
  13062. }
  13063. PageAgent.getResourceContent(this.frameId, this.url, resourceContentLoaded.bind(this));
  13064. },
  13065.  
  13066.  
  13067. isHidden: function()
  13068. {
  13069. return !!this._isHidden;
  13070. },
  13071.  
  13072. __proto__: WebInspector.Object.prototype
  13073. }
  13074.  
  13075.  
  13076.  
  13077.  
  13078.  
  13079.  
  13080.  
  13081. WebInspector.NetworkRequest = function(requestId, url, documentURL, frameId, loaderId)
  13082. {
  13083. this._requestId = requestId;
  13084. this.url = url;
  13085. this._documentURL = documentURL;
  13086. this._frameId = frameId;
  13087. this._loaderId = loaderId;
  13088. this._startTime = -1;
  13089. this._endTime = -1;
  13090.  
  13091. this.statusCode = 0;
  13092. this.statusText = "";
  13093. this.requestMethod = "";
  13094. this.requestTime = 0;
  13095. this.receiveHeadersEnd = 0;
  13096.  
  13097. this._type = WebInspector.resourceTypes.Other;
  13098. this._contentEncoded = false;
  13099. this._pendingContentCallbacks = [];
  13100. this._frames = [];
  13101. }
  13102.  
  13103. WebInspector.NetworkRequest.Events = {
  13104. FinishedLoading: "FinishedLoading",
  13105. TimingChanged: "TimingChanged",
  13106. RequestHeadersChanged: "RequestHeadersChanged",
  13107. ResponseHeadersChanged: "ResponseHeadersChanged",
  13108. }
  13109.  
  13110. WebInspector.NetworkRequest.prototype = {
  13111.  
  13112. get requestId()
  13113. {
  13114. return this._requestId;
  13115. },
  13116.  
  13117. set requestId(requestId)
  13118. {
  13119. this._requestId = requestId;
  13120. },
  13121.  
  13122.  
  13123. get url()
  13124. {
  13125. return this._url;
  13126. },
  13127.  
  13128. set url(x)
  13129. {
  13130. if (this._url === x)
  13131. return;
  13132.  
  13133. this._url = x;
  13134. this._parsedURL = new WebInspector.ParsedURL(x);
  13135. delete this._parsedQueryParameters;
  13136. delete this._name;
  13137. delete this._path;
  13138. },
  13139.  
  13140.  
  13141. get documentURL()
  13142. {
  13143. return this._documentURL;
  13144. },
  13145.  
  13146. get parsedURL()
  13147. {
  13148. return this._parsedURL;
  13149. },
  13150.  
  13151.  
  13152. get frameId()
  13153. {
  13154. return this._frameId;
  13155. },
  13156.  
  13157.  
  13158. get loaderId()
  13159. {
  13160. return this._loaderId;
  13161. },
  13162.  
  13163.  
  13164. get startTime()
  13165. {
  13166. return this._startTime || -1;
  13167. },
  13168.  
  13169. set startTime(x)
  13170. {
  13171. this._startTime = x;
  13172. },
  13173.  
  13174.  
  13175. get responseReceivedTime()
  13176. {
  13177. return this._responseReceivedTime || -1;
  13178. },
  13179.  
  13180. set responseReceivedTime(x)
  13181. {
  13182. this._responseReceivedTime = x;
  13183. },
  13184.  
  13185.  
  13186. get endTime()
  13187. {
  13188. return this._endTime || -1;
  13189. },
  13190.  
  13191. set endTime(x)
  13192. {
  13193. if (this.timing && this.timing.requestTime) {
  13194.  
  13195. this._endTime = Math.max(x, this.responseReceivedTime);
  13196. } else {
  13197.  
  13198. this._endTime = x;
  13199. if (this._responseReceivedTime > x)
  13200. this._responseReceivedTime = x;
  13201. }
  13202. },
  13203.  
  13204.  
  13205. get duration()
  13206. {
  13207. if (this._endTime === -1 || this._startTime === -1)
  13208. return -1;
  13209. return this._endTime - this._startTime;
  13210. },
  13211.  
  13212.  
  13213. get latency()
  13214. {
  13215. if (this._responseReceivedTime === -1 || this._startTime === -1)
  13216. return -1;
  13217. return this._responseReceivedTime - this._startTime;
  13218. },
  13219.  
  13220.  
  13221. get receiveDuration()
  13222. {
  13223. if (this._endTime === -1 || this._responseReceivedTime === -1)
  13224. return -1;
  13225. return this._endTime - this._responseReceivedTime;
  13226. },
  13227.  
  13228.  
  13229. get resourceSize()
  13230. {
  13231. return this._resourceSize || 0;
  13232. },
  13233.  
  13234. set resourceSize(x)
  13235. {
  13236. this._resourceSize = x;
  13237. },
  13238.  
  13239.  
  13240. get transferSize()
  13241. {
  13242. if (this.cached)
  13243. return 0;
  13244. if (this.statusCode === 304) 
  13245. return this.responseHeadersSize;
  13246. if (this._transferSize !== undefined)
  13247. return this._transferSize;
  13248.  
  13249.  
  13250.  
  13251.  
  13252.  
  13253.  
  13254.  
  13255.  
  13256.  
  13257.  
  13258. var bodySize = Number(this.responseHeaderValue("Content-Length") || this.resourceSize);
  13259. return this.responseHeadersSize + bodySize;
  13260. },
  13261.  
  13262.  
  13263. increaseTransferSize: function(x)
  13264. {
  13265. this._transferSize = (this._transferSize || 0) + x;
  13266. },
  13267.  
  13268.  
  13269. get finished()
  13270. {
  13271. return this._finished;
  13272. },
  13273.  
  13274. set finished(x)
  13275. {
  13276. if (this._finished === x)
  13277. return;
  13278.  
  13279. this._finished = x;
  13280.  
  13281. if (x) {
  13282. this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.FinishedLoading, this);
  13283. if (this._pendingContentCallbacks.length)
  13284. this._innerRequestContent();
  13285. }
  13286. },
  13287.  
  13288.  
  13289. get failed()
  13290. {
  13291. return this._failed;
  13292. },
  13293.  
  13294. set failed(x)
  13295. {
  13296. this._failed = x;
  13297. },
  13298.  
  13299.  
  13300. get canceled()
  13301. {
  13302. return this._canceled;
  13303. },
  13304.  
  13305. set canceled(x)
  13306. {
  13307. this._canceled = x;
  13308. },
  13309.  
  13310.  
  13311. get cached()
  13312. {
  13313. return this._cached;
  13314. },
  13315.  
  13316. set cached(x)
  13317. {
  13318. this._cached = x;
  13319. if (x)
  13320. delete this._timing;
  13321. },
  13322.  
  13323.  
  13324. get timing()
  13325. {
  13326. return this._timing;
  13327. },
  13328.  
  13329. set timing(x)
  13330. {
  13331. if (x && !this._cached) {
  13332.  
  13333.  
  13334. this._startTime = x.requestTime;
  13335. this._responseReceivedTime = x.requestTime + x.receiveHeadersEnd / 1000.0;
  13336.  
  13337. this._timing = x;
  13338. this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.TimingChanged, this);
  13339. }
  13340. },
  13341.  
  13342.  
  13343. get mimeType()
  13344. {
  13345. return this._mimeType;
  13346. },
  13347.  
  13348. set mimeType(x)
  13349. {
  13350. this._mimeType = x;
  13351. },
  13352.  
  13353.  
  13354. get displayName()
  13355. {
  13356. return this._parsedURL.displayName;
  13357. },
  13358.  
  13359. name: function()
  13360. {
  13361. if (this._name)
  13362. return this._name;
  13363. this._parseNameAndPathFromURL();
  13364. return this._name;
  13365. },
  13366.  
  13367. path: function()
  13368. {
  13369. if (this._path)
  13370. return this._path;
  13371. this._parseNameAndPathFromURL();
  13372. return this._path;
  13373. },
  13374.  
  13375. _parseNameAndPathFromURL: function()
  13376. {
  13377. if (this._parsedURL.isDataURL()) {
  13378. this._name = this._parsedURL.dataURLDisplayName();
  13379. this._path = "";
  13380. } else if (this._parsedURL.isAboutBlank()) {
  13381. this._name = this._parsedURL.url;
  13382. this._path = "";
  13383. } else {
  13384. this._path = this._parsedURL.host + this._parsedURL.folderPathComponents;
  13385. this._path = this._path.trimURL(WebInspector.inspectedPageDomain ? WebInspector.inspectedPageDomain : "");
  13386. if (this._parsedURL.lastPathComponent || this._parsedURL.queryParams)
  13387. this._name = this._parsedURL.lastPathComponent + (this._parsedURL.queryParams ? "?" + this._parsedURL.queryParams : "");
  13388. else if (this._parsedURL.folderPathComponents) {
  13389. this._name = this._parsedURL.folderPathComponents.substring(this._parsedURL.folderPathComponents.lastIndexOf("/") + 1) + "/";
  13390. this._path = this._path.substring(0, this._path.lastIndexOf("/"));
  13391. } else {
  13392. this._name = this._parsedURL.host;
  13393. this._path = "";
  13394. }
  13395. }
  13396. },
  13397.  
  13398.  
  13399. get folder()
  13400. {
  13401. var path = this._parsedURL.path;
  13402. var indexOfQuery = path.indexOf("?");
  13403. if (indexOfQuery !== -1)
  13404. path = path.substring(0, indexOfQuery);
  13405. var lastSlashIndex = path.lastIndexOf("/");
  13406. return lastSlashIndex !== -1 ? path.substring(0, lastSlashIndex) : "";
  13407. },
  13408.  
  13409.  
  13410. get type()
  13411. {
  13412. return this._type;
  13413. },
  13414.  
  13415. set type(x)
  13416. {
  13417. this._type = x;
  13418. },
  13419.  
  13420.  
  13421. get redirectSource()
  13422. {
  13423. if (this.redirects && this.redirects.length > 0)
  13424. return this.redirects[this.redirects.length - 1];
  13425. return this._redirectSource;
  13426. },
  13427.  
  13428. set redirectSource(x)
  13429. {
  13430. this._redirectSource = x;
  13431. },
  13432.  
  13433.  
  13434. get requestHeaders()
  13435. {
  13436. return this._requestHeaders || [];
  13437. },
  13438.  
  13439. set requestHeaders(x)
  13440. {
  13441. this._requestHeaders = x;
  13442. delete this._sortedRequestHeaders;
  13443. delete this._requestCookies;
  13444.  
  13445. this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.RequestHeadersChanged);
  13446. },
  13447.  
  13448.  
  13449. get requestHeadersText()
  13450. {
  13451. if (typeof this._requestHeadersText === "undefined") {
  13452. this._requestHeadersText = this.requestMethod + " " + this.url + " HTTP/1.1\r\n";
  13453. for (var i = 0; i < this.requestHeaders.length; ++i)
  13454. this._requestHeadersText += this.requestHeaders[i].name + ": " + this.requestHeaders[i].value + "\r\n";
  13455. }
  13456. return this._requestHeadersText;
  13457. },
  13458.  
  13459. set requestHeadersText(x)
  13460. {
  13461. this._requestHeadersText = x;
  13462.  
  13463. this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.RequestHeadersChanged);
  13464. },
  13465.  
  13466.  
  13467. get requestHeadersSize()
  13468. {
  13469. return this.requestHeadersText.length;
  13470. },
  13471.  
  13472.  
  13473. get sortedRequestHeaders()
  13474. {
  13475. if (this._sortedRequestHeaders !== undefined)
  13476. return this._sortedRequestHeaders;
  13477.  
  13478. this._sortedRequestHeaders = [];
  13479. this._sortedRequestHeaders = this.requestHeaders.slice();
  13480. this._sortedRequestHeaders.sort(function(a,b) { return a.name.toLowerCase().localeCompare(b.name.toLowerCase()) });
  13481. return this._sortedRequestHeaders;
  13482. },
  13483.  
  13484.  
  13485. requestHeaderValue: function(headerName)
  13486. {
  13487. return this._headerValue(this.requestHeaders, headerName);
  13488. },
  13489.  
  13490.  
  13491. get requestCookies()
  13492. {
  13493. if (!this._requestCookies)
  13494. this._requestCookies = WebInspector.CookieParser.parseCookie(this.requestHeaderValue("Cookie"));
  13495. return this._requestCookies;
  13496. },
  13497.  
  13498.  
  13499. get requestFormData()
  13500. {
  13501. return this._requestFormData;
  13502. },
  13503.  
  13504. set requestFormData(x)
  13505. {
  13506. this._requestFormData = x;
  13507. delete this._parsedFormParameters;
  13508. },
  13509.  
  13510.  
  13511. get requestHttpVersion()
  13512. {
  13513. var firstLine = this.requestHeadersText.split(/\r\n/)[0];
  13514. var match = firstLine.match(/(HTTP\/\d+\.\d+)$/);
  13515. return match ? match[1] : undefined;
  13516. },
  13517.  
  13518.  
  13519. get responseHeaders()
  13520. {
  13521. return this._responseHeaders || [];
  13522. },
  13523.  
  13524. set responseHeaders(x)
  13525. {
  13526. this._responseHeaders = x;
  13527. delete this._sortedResponseHeaders;
  13528. delete this._responseCookies;
  13529.  
  13530. this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.ResponseHeadersChanged);
  13531. },
  13532.  
  13533.  
  13534. get responseHeadersText()
  13535. {
  13536. if (typeof this._responseHeadersText === "undefined") {
  13537. this._responseHeadersText = "HTTP/1.1 " + this.statusCode + " " + this.statusText + "\r\n";
  13538. for (var i = 0; i < this.responseHeaders.length; ++i)
  13539. this._responseHeadersText += this.responseHeaders[i].name + ": " + this.responseHeaders[i].value + "\r\n";
  13540. }
  13541. return this._responseHeadersText;
  13542. },
  13543.  
  13544. set responseHeadersText(x)
  13545. {
  13546. this._responseHeadersText = x;
  13547.  
  13548. this.dispatchEventToListeners(WebInspector.NetworkRequest.Events.ResponseHeadersChanged);
  13549. },
  13550.  
  13551.  
  13552. get responseHeadersSize()
  13553. {
  13554. return this.responseHeadersText.length;
  13555. },
  13556.  
  13557.  
  13558. get sortedResponseHeaders()
  13559. {
  13560. if (this._sortedResponseHeaders !== undefined)
  13561. return this._sortedResponseHeaders;
  13562.  
  13563. this._sortedResponseHeaders = [];
  13564. this._sortedResponseHeaders = this.responseHeaders.slice();
  13565. this._sortedResponseHeaders.sort(function(a,b) { return a.name.toLowerCase().localeCompare(b.name.toLowerCase()) });
  13566. return this._sortedResponseHeaders;
  13567. },
  13568.  
  13569.  
  13570. responseHeaderValue: function(headerName)
  13571. {
  13572. return this._headerValue(this.responseHeaders, headerName);
  13573. },
  13574.  
  13575.  
  13576. get responseCookies()
  13577. {
  13578. if (!this._responseCookies)
  13579. this._responseCookies = WebInspector.CookieParser.parseSetCookie(this.responseHeaderValue("Set-Cookie"));
  13580. return this._responseCookies;
  13581. },
  13582.  
  13583.  
  13584. queryString: function()
  13585. {
  13586. if (this._queryString)
  13587. return this._queryString;
  13588. var queryString = this.url.split("?", 2)[1];
  13589. if (!queryString)
  13590. return null;
  13591. this._queryString = queryString.split("#", 2)[0];
  13592. return this._queryString;
  13593. },
  13594.  
  13595.  
  13596. get queryParameters()
  13597. {
  13598. if (this._parsedQueryParameters)
  13599. return this._parsedQueryParameters;
  13600. var queryString = this.queryString();
  13601. if (!queryString)
  13602. return null;
  13603. this._parsedQueryParameters = this._parseParameters(queryString);
  13604. return this._parsedQueryParameters;
  13605. },
  13606.  
  13607.  
  13608. get formParameters()
  13609. {
  13610. if (this._parsedFormParameters)
  13611. return this._parsedFormParameters;
  13612. if (!this.requestFormData)
  13613. return null;
  13614. var requestContentType = this.requestContentType();
  13615. if (!requestContentType || !requestContentType.match(/^application\/x-www-form-urlencoded\s*(;.*)?$/i))
  13616. return null;
  13617. this._parsedFormParameters = this._parseParameters(this.requestFormData);
  13618. return this._parsedFormParameters;
  13619. },
  13620.  
  13621.  
  13622. get responseHttpVersion()
  13623. {
  13624. var match = this.responseHeadersText.match(/^(HTTP\/\d+\.\d+)/);
  13625. return match ? match[1] : undefined;
  13626. },
  13627.  
  13628.  
  13629. _parseParameters: function(queryString)
  13630. {
  13631. function parseNameValue(pair)
  13632. {
  13633. var parameter = {};
  13634. var splitPair = pair.split("=", 2);
  13635.  
  13636. parameter.name = splitPair[0];
  13637. if (splitPair.length === 1)
  13638. parameter.value = "";
  13639. else
  13640. parameter.value = splitPair[1];
  13641. return parameter;
  13642. }
  13643. return queryString.split("&").map(parseNameValue);
  13644. },
  13645.  
  13646.  
  13647. _headerValue: function(headers, headerName)
  13648. {
  13649. headerName = headerName.toLowerCase();
  13650.  
  13651. var values = [];
  13652. for (var i = 0; i < headers.length; ++i) {
  13653. if (headers[i].name.toLowerCase() === headerName)
  13654. values.push(headers[i].value);
  13655. }
  13656. if (!values.length)
  13657. return undefined;
  13658.  
  13659. if (headerName === "set-cookie")
  13660. return values.join("\n");
  13661. return values.join(", ");
  13662. },
  13663.  
  13664.  
  13665. get content()
  13666. {
  13667. return this._content;
  13668. },
  13669.  
  13670.  
  13671. get contentEncoded()
  13672. {
  13673. return this._contentEncoded;
  13674. },
  13675.  
  13676.  
  13677. contentURL: function()
  13678. {
  13679. return this._url;
  13680. },
  13681.  
  13682.  
  13683. contentType: function()
  13684. {
  13685. return this._type;
  13686. },
  13687.  
  13688.  
  13689. requestContent: function(callback)
  13690. {
  13691.  
  13692.  
  13693.  
  13694. if (this.type === WebInspector.resourceTypes.WebSocket) {
  13695. callback(null, false, this._mimeType);
  13696. return;
  13697. }
  13698. if (typeof this._content !== "undefined") {
  13699. callback(this.content || null, this._contentEncoded, this._mimeType);
  13700. return;
  13701. }
  13702. this._pendingContentCallbacks.push(callback);
  13703. if (this.finished)
  13704. this._innerRequestContent();
  13705. },
  13706.  
  13707.  
  13708. searchInContent: function(query, caseSensitive, isRegex, callback)
  13709. {
  13710. callback([]);
  13711. },
  13712.  
  13713.  
  13714. isHttpFamily: function()
  13715. {
  13716. return !!this.url.match(/^https?:/i);
  13717. },
  13718.  
  13719.  
  13720. requestContentType: function()
  13721. {
  13722. return this.requestHeaderValue("Content-Type");
  13723. },
  13724.  
  13725.  
  13726. isPingRequest: function()
  13727. {
  13728. return "text/ping" === this.requestContentType();
  13729. },
  13730.  
  13731.  
  13732. hasErrorStatusCode: function()
  13733. {
  13734. return this.statusCode >= 400;
  13735. },
  13736.  
  13737.  
  13738. populateImageSource: function(image)
  13739. {
  13740.  
  13741. function onResourceContent(content, contentEncoded, mimeType)
  13742. {
  13743. var imageSrc = this.asDataURL();
  13744. if (imageSrc === null)
  13745. imageSrc = this.url;
  13746. image.src = imageSrc;
  13747. }
  13748.  
  13749. this.requestContent(onResourceContent.bind(this));
  13750. },
  13751.  
  13752.  
  13753. asDataURL: function()
  13754. {
  13755. return WebInspector.contentAsDataURL(this._content, this.mimeType, this._contentEncoded);
  13756. },
  13757.  
  13758. _innerRequestContent: function()
  13759. {
  13760. if (this._contentRequested)
  13761. return;
  13762. this._contentRequested = true;
  13763.  
  13764.  
  13765. function onResourceContent(error, content, contentEncoded)
  13766. {
  13767. this._content = error ? null : content;
  13768. this._contentEncoded = contentEncoded;
  13769. var callbacks = this._pendingContentCallbacks.slice();
  13770. for (var i = 0; i < callbacks.length; ++i)
  13771. callbacks[i](this._content, this._contentEncoded, this._mimeType);
  13772. this._pendingContentCallbacks.length = 0;
  13773. delete this._contentRequested;
  13774. }
  13775. NetworkAgent.getResponseBody(this._requestId, onResourceContent.bind(this));
  13776. },
  13777.  
  13778.  
  13779. frames: function()
  13780. {
  13781. return this._frames;
  13782. },
  13783.  
  13784.  
  13785. frame: function(position)
  13786. {
  13787. return this._frames[position];
  13788. },
  13789.  
  13790.  
  13791. addFrameError: function(errorMessage, time)
  13792. {
  13793. var errorObject = {};
  13794. errorObject.errorMessage = errorMessage;
  13795. errorObject.time = time;
  13796. this._pushFrame(errorObject);
  13797. },
  13798.  
  13799.  
  13800. addFrame: function(response, time, sent)
  13801. {
  13802. response.time = time;
  13803. if (sent)
  13804. response.sent = true;
  13805. this._pushFrame(response);
  13806. },
  13807.  
  13808. _pushFrame: function(object)
  13809. {
  13810. if (this._frames.length >= 100) {
  13811. this._frames.splice(0, 10);
  13812. }
  13813. this._frames.push(object);
  13814. },
  13815.  
  13816. __proto__: WebInspector.Object.prototype
  13817. }
  13818.  
  13819.  
  13820.  
  13821.  
  13822.  
  13823.  
  13824.  
  13825. WebInspector.UISourceCode = function(workspace, url, contentType, isEditable)
  13826. {
  13827. this._workspace = workspace;
  13828. this._url = url;
  13829. this._parsedURL = new WebInspector.ParsedURL(url);
  13830. this._contentType = contentType;
  13831. this._isEditable = isEditable;
  13832.  
  13833. this._requestContentCallbacks = [];
  13834.  
  13835. this._liveLocations = [];
  13836.  
  13837. this._consoleMessages = [];
  13838.  
  13839.  
  13840. this.history = [];
  13841. if (this.isEditable() && this._url)
  13842. this._restoreRevisionHistory();
  13843. this._formatterMapping = new WebInspector.IdentityFormatterSourceMapping();
  13844. }
  13845.  
  13846. WebInspector.UISourceCode.Events = {
  13847. FormattedChanged: "FormattedChanged",
  13848. WorkingCopyChanged: "WorkingCopyChanged",
  13849. WorkingCopyCommitted: "WorkingCopyCommitted",
  13850. TitleChanged: "TitleChanged",
  13851. ConsoleMessageAdded: "ConsoleMessageAdded",
  13852. ConsoleMessageRemoved: "ConsoleMessageRemoved",
  13853. ConsoleMessagesCleared: "ConsoleMessagesCleared",
  13854. SourceMappingChanged: "SourceMappingChanged",
  13855. }
  13856.  
  13857. WebInspector.UISourceCode.prototype = {
  13858.  
  13859. get url()
  13860. {
  13861. return this._url;
  13862. },
  13863.  
  13864.  
  13865. urlChanged: function(url)
  13866. {
  13867. this._url = url;
  13868. this._parsedURL = new WebInspector.ParsedURL(this._url);
  13869. this.dispatchEventToListeners(WebInspector.UISourceCode.Events.TitleChanged, null);
  13870. },
  13871.  
  13872.  
  13873. get parsedURL()
  13874. {
  13875. return this._parsedURL;
  13876. },
  13877.  
  13878.  
  13879. contentURL: function()
  13880. {
  13881. return this._url;
  13882. },
  13883.  
  13884.  
  13885. contentType: function()
  13886. {
  13887. return this._contentType;
  13888. },
  13889.  
  13890.  
  13891. scriptFile: function()
  13892. {
  13893. return this._scriptFile;
  13894. },
  13895.  
  13896.  
  13897. setScriptFile: function(scriptFile)
  13898. {
  13899. this._scriptFile = scriptFile;
  13900. },
  13901.  
  13902.  
  13903. styleFile: function()
  13904. {
  13905. return this._styleFile;
  13906. },
  13907.  
  13908.  
  13909. setStyleFile: function(styleFile)
  13910. {
  13911. this._styleFile = styleFile;
  13912. },
  13913.  
  13914.  
  13915. requestContent: function(callback)
  13916. {
  13917. if (this._content || this._contentLoaded) {
  13918. callback(this._content, false, this._mimeType);
  13919. return;
  13920. }
  13921. this._requestContentCallbacks.push(callback);
  13922. if (this._requestContentCallbacks.length === 1)
  13923. this._workspace.requestFileContent(this, this._fireContentAvailable.bind(this));
  13924. },
  13925.  
  13926.  
  13927. requestOriginalContent: function(callback)
  13928. {
  13929. this._workspace.requestFileContent(this, callback);
  13930. },
  13931.  
  13932.  
  13933. _commitContent: function(content)
  13934. {
  13935. this._content = content;
  13936. this._contentLoaded = true;
  13937.  
  13938. var lastRevision = this.history.length ? this.history[this.history.length - 1] : null;
  13939. if (!lastRevision || lastRevision._content !== this._content) {
  13940. var revision = new WebInspector.Revision(this, this._content, new Date());
  13941. this.history.push(revision);
  13942. revision._persist();
  13943. }
  13944.  
  13945. var oldWorkingCopy = this._workingCopy;
  13946. delete this._workingCopy;
  13947. this.dispatchEventToListeners(WebInspector.UISourceCode.Events.WorkingCopyCommitted, {oldWorkingCopy: oldWorkingCopy, workingCopy: this.workingCopy()});
  13948. this._workspace.dispatchEventToListeners(WebInspector.Workspace.Events.UISourceCodeContentCommitted, { uiSourceCode: this, content: this._content });
  13949. if (this._url && WebInspector.fileManager.isURLSaved(this._url)) {
  13950. WebInspector.fileManager.save(this._url, this._content, false);
  13951. WebInspector.fileManager.close(this._url);
  13952. }
  13953. },
  13954.  
  13955.  
  13956. addRevision: function(content)
  13957. {
  13958. this._commitContent(content);
  13959. },
  13960.  
  13961. _restoreRevisionHistory: function()
  13962. {
  13963. if (!window.localStorage)
  13964. return;
  13965.  
  13966. var registry = WebInspector.Revision._revisionHistoryRegistry();
  13967. var historyItems = registry[this.url];
  13968. if (!historyItems || !historyItems.length)
  13969. return;
  13970. for (var i = 0; i < historyItems.length; ++i) {
  13971. var content = window.localStorage[historyItems[i].key];
  13972. var timestamp = new Date(historyItems[i].timestamp);
  13973. var revision = new WebInspector.Revision(this, content, timestamp);
  13974. this.history.push(revision);
  13975. }
  13976. this._content = this.history[this.history.length - 1].content;
  13977. this._contentLoaded = true;
  13978. this._mimeType = this.canonicalMimeType();
  13979. },
  13980.  
  13981. _clearRevisionHistory: function()
  13982. {
  13983. if (!window.localStorage)
  13984. return;
  13985.  
  13986. var registry = WebInspector.Revision._revisionHistoryRegistry();
  13987. var historyItems = registry[this.url];
  13988. for (var i = 0; historyItems && i < historyItems.length; ++i)
  13989. delete window.localStorage[historyItems[i].key];
  13990. delete registry[this.url];
  13991. window.localStorage["revision-history"] = JSON.stringify(registry);
  13992. },
  13993.  
  13994. revertToOriginal: function()
  13995. {
  13996.  
  13997. function callback(content, contentEncoded, mimeType)
  13998. {
  13999. if (typeof content !== "string")
  14000. return;
  14001.  
  14002. this.addRevision(content);
  14003. }
  14004.  
  14005. this.requestOriginalContent(callback.bind(this));
  14006.  
  14007. WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
  14008. action: WebInspector.UserMetrics.UserActionNames.ApplyOriginalContent,
  14009. url: this.url
  14010. });
  14011. },
  14012.  
  14013.  
  14014. revertAndClearHistory: function(callback)
  14015. {
  14016.  
  14017. function revert(content, contentEncoded, mimeType)
  14018. {
  14019. if (typeof content !== "string")
  14020. return;
  14021.  
  14022. this.addRevision(content);
  14023. this._clearRevisionHistory();
  14024. this.history = [];
  14025. callback(this);
  14026. }
  14027.  
  14028. this.requestOriginalContent(revert.bind(this));
  14029.  
  14030. WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
  14031. action: WebInspector.UserMetrics.UserActionNames.RevertRevision,
  14032. url: this.url
  14033. });
  14034. },
  14035.  
  14036.  
  14037. isEditable: function()
  14038. {
  14039. return this._isEditable;
  14040. },
  14041.  
  14042.  
  14043. workingCopy: function()
  14044. {
  14045. if (this.isDirty())
  14046. return this._workingCopy;
  14047. return this._content;
  14048. },
  14049.  
  14050.  
  14051. setWorkingCopy: function(newWorkingCopy)
  14052. {
  14053. var wasDirty = this.isDirty();        
  14054. this._mimeType = this.canonicalMimeType();
  14055. var oldWorkingCopy = this._workingCopy;
  14056. if (this._content === newWorkingCopy)
  14057. delete this._workingCopy;
  14058. else
  14059. this._workingCopy = newWorkingCopy;
  14060. this.dispatchEventToListeners(WebInspector.UISourceCode.Events.WorkingCopyChanged, {oldWorkingCopy: oldWorkingCopy, workingCopy: this.workingCopy(), wasDirty: wasDirty});
  14061. },
  14062.  
  14063.  
  14064. commitWorkingCopy: function(callback)
  14065. {
  14066. if (!this.isDirty()) {
  14067. callback(null);
  14068. return;
  14069. }
  14070.  
  14071. this._commitContent(this._workingCopy);
  14072. callback(null);
  14073.  
  14074. WebInspector.notifications.dispatchEventToListeners(WebInspector.UserMetrics.UserAction, {
  14075. action: WebInspector.UserMetrics.UserActionNames.FileSaved,
  14076. url: this.url
  14077. });
  14078. },
  14079.  
  14080.  
  14081. isDirty: function()
  14082. {
  14083. return typeof this._workingCopy !== "undefined" && this._workingCopy !== this._content;
  14084. },
  14085.  
  14086.  
  14087. mimeType: function()
  14088. {
  14089. return this._mimeType;
  14090. },
  14091.  
  14092.  
  14093. canonicalMimeType: function()
  14094. {
  14095. return this.contentType().canonicalMimeType() || this._mimeType;
  14096. },
  14097.  
  14098.  
  14099. content: function()
  14100. {
  14101. return this._content;
  14102. },
  14103.  
  14104.  
  14105. searchInContent: function(query, caseSensitive, isRegex, callback)
  14106. {
  14107. var content = this.content();
  14108. if (content) {
  14109. var provider = new WebInspector.StaticContentProvider(this.contentType(), content);
  14110. provider.searchInContent(query, caseSensitive, isRegex, callback);
  14111. return;
  14112. }
  14113.  
  14114. this._workspace.searchInFileContent(this, query, caseSensitive, isRegex, callback);
  14115. },
  14116.  
  14117.  
  14118. _fireContentAvailable: function(content, contentEncoded, mimeType)
  14119. {
  14120. this._contentLoaded = true;
  14121. this._mimeType = mimeType;
  14122. this._content = content;
  14123.  
  14124. var callbacks = this._requestContentCallbacks.slice();
  14125. this._requestContentCallbacks = [];
  14126. for (var i = 0; i < callbacks.length; ++i)
  14127. callbacks[i](content, contentEncoded, mimeType);
  14128.  
  14129. if (this._formatOnLoad) {
  14130. delete this._formatOnLoad;
  14131. this.setFormatted(true);
  14132. }
  14133. },
  14134.  
  14135.  
  14136. contentLoaded: function()
  14137. {
  14138. return this._contentLoaded;
  14139. },
  14140.  
  14141.  
  14142. uiLocationToRawLocation: function(lineNumber, columnNumber)
  14143. {
  14144. if (!this._sourceMapping)
  14145. return null;
  14146. var location = this._formatterMapping.formattedToOriginal(lineNumber, columnNumber);
  14147. return this._sourceMapping.uiLocationToRawLocation(this, location[0], location[1]);
  14148. },
  14149.  
  14150.  
  14151. addLiveLocation: function(liveLocation)
  14152. {
  14153. this._liveLocations.push(liveLocation);
  14154. },
  14155.  
  14156.  
  14157. removeLiveLocation: function(liveLocation)
  14158. {
  14159. this._liveLocations.remove(liveLocation);
  14160. },
  14161.  
  14162. updateLiveLocations: function()
  14163. {
  14164. var locationsCopy = this._liveLocations.slice();
  14165. for (var i = 0; i < locationsCopy.length; ++i)
  14166. locationsCopy[i].update();
  14167. },
  14168.  
  14169.  
  14170. overrideLocation: function(uiLocation)
  14171. {
  14172. var location = this._formatterMapping.originalToFormatted(uiLocation.lineNumber, uiLocation.columnNumber);
  14173. uiLocation.lineNumber = location[0];
  14174. uiLocation.columnNumber = location[1];
  14175. return uiLocation;
  14176. },
  14177.  
  14178.  
  14179. consoleMessages: function()
  14180. {
  14181. return this._consoleMessages;
  14182. },
  14183.  
  14184.  
  14185. consoleMessageAdded: function(message)
  14186. {
  14187. this._consoleMessages.push(message);
  14188. this.dispatchEventToListeners(WebInspector.UISourceCode.Events.ConsoleMessageAdded, message);
  14189. },
  14190.  
  14191.  
  14192. consoleMessageRemoved: function(message)
  14193. {
  14194. this._consoleMessages.remove(message);
  14195. this.dispatchEventToListeners(WebInspector.UISourceCode.Events.ConsoleMessageRemoved, message);
  14196. },
  14197.  
  14198. consoleMessagesCleared: function()
  14199. {
  14200. this._consoleMessages = [];
  14201. this.dispatchEventToListeners(WebInspector.UISourceCode.Events.ConsoleMessagesCleared);
  14202. },
  14203.  
  14204.  
  14205. formatted: function()
  14206. {
  14207. return !!this._formatted;
  14208. },
  14209.  
  14210.  
  14211. setFormatted: function(formatted)
  14212. {
  14213. if (!this.contentLoaded()) {
  14214. this._formatOnLoad = formatted;
  14215. return;
  14216. }
  14217.  
  14218. if (this._formatted === formatted)
  14219. return;
  14220.  
  14221. this._formatted = formatted;
  14222.  
  14223.  
  14224. this._contentLoaded = false;
  14225. this._content = false;
  14226. WebInspector.UISourceCode.prototype.requestContent.call(this, didGetContent.bind(this));
  14227.  
  14228.  
  14229. function didGetContent(content, contentEncoded, mimeType)
  14230. {
  14231. var formatter;
  14232. if (!formatted)
  14233. formatter = new WebInspector.IdentityFormatter();
  14234. else
  14235. formatter = WebInspector.Formatter.createFormatter(this.contentType());
  14236. formatter.formatContent(mimeType, content || "", formattedChanged.bind(this));
  14237.  
  14238.  
  14239. function formattedChanged(content, formatterMapping)
  14240. {
  14241. this._content = content;
  14242. delete this._workingCopy;
  14243. this._formatterMapping = formatterMapping;
  14244. this.dispatchEventToListeners(WebInspector.UISourceCode.Events.FormattedChanged, {content: content});
  14245. this.updateLiveLocations();
  14246. }
  14247. }
  14248. },
  14249.  
  14250.  
  14251. createFormatter: function()
  14252. {
  14253.  
  14254. return null;
  14255. },
  14256.  
  14257.  
  14258. setSourceMapping: function(sourceMapping)
  14259. {
  14260. this._sourceMapping = sourceMapping;
  14261. this.dispatchEventToListeners(WebInspector.UISourceCode.Events.SourceMappingChanged, null);
  14262. },
  14263.  
  14264. __proto__: WebInspector.Object.prototype
  14265. }
  14266.  
  14267.  
  14268. WebInspector.UISourceCodeProvider = function()
  14269. {
  14270. }
  14271.  
  14272. WebInspector.UISourceCodeProvider.Events = {
  14273. UISourceCodeAdded: "UISourceCodeAdded",
  14274. TemporaryUISourceCodeAdded: "TemporaryUISourceCodeAdded",
  14275. TemporaryUISourceCodeRemoved: "TemporaryUISourceCodeRemoved",
  14276. UISourceCodeRemoved: "UISourceCodeRemoved"
  14277. }
  14278.  
  14279. WebInspector.UISourceCodeProvider.prototype = {
  14280.  
  14281. uiSourceCodes: function() {},
  14282.  
  14283.  
  14284. addEventListener: function(eventType, listener, thisObject) { },
  14285.  
  14286.  
  14287. removeEventListener: function(eventType, listener, thisObject) { }
  14288. }
  14289.  
  14290.  
  14291. WebInspector.UILocation = function(uiSourceCode, lineNumber, columnNumber)
  14292. {
  14293. this.uiSourceCode = uiSourceCode;
  14294. this.lineNumber = lineNumber;
  14295. this.columnNumber = columnNumber;
  14296. }
  14297.  
  14298. WebInspector.UILocation.prototype = {
  14299.  
  14300. uiLocationToRawLocation: function()
  14301. {
  14302. return this.uiSourceCode.uiLocationToRawLocation(this.lineNumber, this.columnNumber);
  14303. },
  14304.  
  14305.  
  14306. url: function()
  14307. {
  14308. return this.uiSourceCode.contentURL();
  14309. }
  14310. }
  14311.  
  14312.  
  14313. WebInspector.RawLocation = function()
  14314. {
  14315. }
  14316.  
  14317.  
  14318. WebInspector.LiveLocation = function(rawLocation, updateDelegate)
  14319. {
  14320. this._rawLocation = rawLocation;
  14321. this._updateDelegate = updateDelegate;
  14322. this._uiSourceCodes = [];
  14323. }
  14324.  
  14325. WebInspector.LiveLocation.prototype = {
  14326. update: function()
  14327. {
  14328. var uiLocation = this.uiLocation();
  14329. if (uiLocation) {
  14330. var uiSourceCode = uiLocation.uiSourceCode;
  14331. if (this._uiSourceCodes.indexOf(uiSourceCode) === -1) {
  14332. uiSourceCode.addLiveLocation(this);
  14333. this._uiSourceCodes.push(uiSourceCode);
  14334. }
  14335. var oneTime = this._updateDelegate(uiLocation);
  14336. if (oneTime)
  14337. this.dispose();
  14338. }
  14339. },
  14340.  
  14341.  
  14342. rawLocation: function()
  14343. {
  14344. return this._rawLocation;
  14345. },
  14346.  
  14347.  
  14348. uiLocation: function()
  14349. {
  14350.  
  14351. },
  14352.  
  14353. dispose: function()
  14354. {
  14355. for (var i = 0; i < this._uiSourceCodes.length; ++i)
  14356. this._uiSourceCodes[i].removeLiveLocation(this);
  14357. this._uiSourceCodes = [];
  14358. }
  14359. }
  14360.  
  14361.  
  14362. WebInspector.Revision = function(uiSourceCode, content, timestamp)
  14363. {
  14364. this._uiSourceCode = uiSourceCode;
  14365. this._content = content;
  14366. this._timestamp = timestamp;
  14367. }
  14368.  
  14369. WebInspector.Revision._revisionHistoryRegistry = function()
  14370. {
  14371. if (!WebInspector.Revision._revisionHistoryRegistryObject) {
  14372. if (window.localStorage) {
  14373. var revisionHistory = window.localStorage["revision-history"];
  14374. try {
  14375. WebInspector.Revision._revisionHistoryRegistryObject = revisionHistory ? JSON.parse(revisionHistory) : {};
  14376. } catch (e) {
  14377. WebInspector.Revision._revisionHistoryRegistryObject = {};
  14378. }
  14379. } else
  14380. WebInspector.Revision._revisionHistoryRegistryObject = {};
  14381. }
  14382. return WebInspector.Revision._revisionHistoryRegistryObject;
  14383. }
  14384.  
  14385. WebInspector.Revision.filterOutStaleRevisions = function()
  14386. {
  14387. if (!window.localStorage)
  14388. return;
  14389.  
  14390. var registry = WebInspector.Revision._revisionHistoryRegistry();
  14391. var filteredRegistry = {};
  14392. for (var url in registry) {
  14393. var historyItems = registry[url];
  14394. var filteredHistoryItems = [];
  14395. for (var i = 0; historyItems && i < historyItems.length; ++i) {
  14396. var historyItem = historyItems[i];
  14397. if (historyItem.loaderId === WebInspector.resourceTreeModel.mainFrame.loaderId) {
  14398. filteredHistoryItems.push(historyItem);
  14399. filteredRegistry[url] = filteredHistoryItems;
  14400. } else
  14401. delete window.localStorage[historyItem.key];
  14402. }
  14403. }
  14404. WebInspector.Revision._revisionHistoryRegistryObject = filteredRegistry;
  14405.  
  14406. function persist()
  14407. {
  14408. window.localStorage["revision-history"] = JSON.stringify(filteredRegistry);
  14409. }
  14410.  
  14411.  
  14412. setTimeout(persist, 0);
  14413. }
  14414.  
  14415. WebInspector.Revision.prototype = {
  14416.  
  14417. get uiSourceCode()
  14418. {
  14419. return this._uiSourceCode;
  14420. },
  14421.  
  14422.  
  14423. get timestamp()
  14424. {
  14425. return this._timestamp;
  14426. },
  14427.  
  14428.  
  14429. get content()
  14430. {
  14431. return this._content || null;
  14432. },
  14433.  
  14434. revertToThis: function()
  14435. {
  14436. function revert(content)
  14437. {
  14438. if (this._uiSourceCode._content !== content)
  14439. this._uiSourceCode.addRevision(content);
  14440. }
  14441. this.requestContent(revert.bind(this));
  14442. },
  14443.  
  14444.  
  14445. contentURL: function()
  14446. {
  14447. return this._uiSourceCode.url;
  14448. },
  14449.  
  14450.  
  14451. contentType: function()
  14452. {
  14453. return this._uiSourceCode.contentType();
  14454. },
  14455.  
  14456.  
  14457. requestContent: function(callback)
  14458. {
  14459. callback(this._content || "", false, this.uiSourceCode.canonicalMimeType());
  14460. },
  14461.  
  14462.  
  14463. searchInContent: function(query, caseSensitive, isRegex, callback)
  14464. {
  14465. callback([]);
  14466. },
  14467.  
  14468. _persist: function()
  14469. {
  14470. if (!window.localStorage)
  14471. return;
  14472.  
  14473. var url = this.contentURL();
  14474. if (!url || url.startsWith("inspector://"))
  14475. return;
  14476.  
  14477. var loaderId = WebInspector.resourceTreeModel.mainFrame.loaderId;
  14478. var timestamp = this.timestamp.getTime();
  14479. var key = "revision-history|" + url + "|" + loaderId + "|" + timestamp;
  14480.  
  14481. var registry = WebInspector.Revision._revisionHistoryRegistry();
  14482.  
  14483. var historyItems = registry[url];
  14484. if (!historyItems) {
  14485. historyItems = [];
  14486. registry[url] = historyItems;
  14487. }
  14488. historyItems.push({url: url, loaderId: loaderId, timestamp: timestamp, key: key});
  14489.  
  14490. function persist()
  14491. {
  14492. window.localStorage[key] = this._content;
  14493. window.localStorage["revision-history"] = JSON.stringify(registry);
  14494. }
  14495.  
  14496.  
  14497. setTimeout(persist.bind(this), 0);
  14498. }
  14499. }
  14500.  
  14501.  
  14502.  
  14503.  
  14504.  
  14505.  
  14506. WebInspector.CSSStyleModel = function()
  14507. {
  14508. this._pendingCommandsMajorState = [];
  14509.  
  14510. this._locations = [];
  14511. this._sourceMappings = {};
  14512. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.UndoRedoRequested, this._undoRedoRequested, this);
  14513. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.UndoRedoCompleted, this._undoRedoCompleted, this);
  14514. this._resourceBinding = new WebInspector.CSSStyleModelResourceBinding();
  14515. this._namedFlowCollections = {};
  14516. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.DocumentUpdated, this._resetNamedFlowCollections, this);
  14517. InspectorBackend.registerCSSDispatcher(new WebInspector.CSSDispatcher(this));
  14518. CSSAgent.enable();
  14519. }
  14520.  
  14521.  
  14522. WebInspector.CSSStyleModel.parseRuleArrayPayload = function(ruleArray)
  14523. {
  14524. var result = [];
  14525. for (var i = 0; i < ruleArray.length; ++i)
  14526. result.push(WebInspector.CSSRule.parsePayload(ruleArray[i]));
  14527. return result;
  14528. }
  14529.  
  14530.  
  14531. WebInspector.CSSStyleModel.parseRuleMatchArrayPayload = function(matchArray)
  14532. {
  14533. var result = [];
  14534. for (var i = 0; i < matchArray.length; ++i)
  14535. result.push(WebInspector.CSSRule.parsePayload(matchArray[i].rule, matchArray[i].matchingSelectors));
  14536. return result;
  14537. }
  14538.  
  14539. WebInspector.CSSStyleModel.Events = {
  14540. StyleSheetChanged: "StyleSheetChanged",
  14541. MediaQueryResultChanged: "MediaQueryResultChanged",
  14542. NamedFlowCreated: "NamedFlowCreated",
  14543. NamedFlowRemoved: "NamedFlowRemoved",
  14544. RegionLayoutUpdated: "RegionLayoutUpdated"
  14545. }
  14546.  
  14547. WebInspector.CSSStyleModel.MediaTypes = ["all", "braille", "embossed", "handheld", "print", "projection", "screen", "speech", "tty", "tv"];
  14548.  
  14549. WebInspector.CSSStyleModel.prototype = {
  14550.  
  14551. getMatchedStylesAsync: function(nodeId, needPseudo, needInherited, userCallback)
  14552. {
  14553.  
  14554. function callback(userCallback, error, matchedPayload, pseudoPayload, inheritedPayload)
  14555. {
  14556. if (error) {
  14557. if (userCallback)
  14558. userCallback(null);
  14559. return;
  14560. }
  14561.  
  14562. var result = {};
  14563. if (matchedPayload)
  14564. result.matchedCSSRules = WebInspector.CSSStyleModel.parseRuleMatchArrayPayload(matchedPayload);
  14565.  
  14566. if (pseudoPayload) {
  14567. result.pseudoElements = [];
  14568. for (var i = 0; i < pseudoPayload.length; ++i) {
  14569. var entryPayload = pseudoPayload[i];
  14570. result.pseudoElements.push({ pseudoId: entryPayload.pseudoId, rules: WebInspector.CSSStyleModel.parseRuleMatchArrayPayload(entryPayload.matches) });
  14571. }
  14572. }
  14573.  
  14574. if (inheritedPayload) {
  14575. result.inherited = [];
  14576. for (var i = 0; i < inheritedPayload.length; ++i) {
  14577. var entryPayload = inheritedPayload[i];
  14578. var entry = {};
  14579. if (entryPayload.inlineStyle)
  14580. entry.inlineStyle = WebInspector.CSSStyleDeclaration.parsePayload(entryPayload.inlineStyle);
  14581. if (entryPayload.matchedCSSRules)
  14582. entry.matchedCSSRules = WebInspector.CSSStyleModel.parseRuleMatchArrayPayload(entryPayload.matchedCSSRules);
  14583. result.inherited.push(entry);
  14584. }
  14585. }
  14586.  
  14587. if (userCallback)
  14588. userCallback(result);
  14589. }
  14590.  
  14591. CSSAgent.getMatchedStylesForNode(nodeId, needPseudo, needInherited, callback.bind(null, userCallback));
  14592. },
  14593.  
  14594.  
  14595. getComputedStyleAsync: function(nodeId, userCallback)
  14596. {
  14597.  
  14598. function callback(userCallback, error, computedPayload)
  14599. {
  14600. if (error || !computedPayload)
  14601. userCallback(null);
  14602. else
  14603. userCallback(WebInspector.CSSStyleDeclaration.parseComputedStylePayload(computedPayload));
  14604. }
  14605.  
  14606. CSSAgent.getComputedStyleForNode(nodeId, callback.bind(null, userCallback));
  14607. },
  14608.  
  14609.  
  14610. getInlineStylesAsync: function(nodeId, userCallback)
  14611. {
  14612.  
  14613. function callback(userCallback, error, inlinePayload, attributesStylePayload)
  14614. {
  14615. if (error || !inlinePayload)
  14616. userCallback(null, null);
  14617. else
  14618. userCallback(WebInspector.CSSStyleDeclaration.parsePayload(inlinePayload), attributesStylePayload ? WebInspector.CSSStyleDeclaration.parsePayload(attributesStylePayload) : null);
  14619. }
  14620.  
  14621. CSSAgent.getInlineStylesForNode(nodeId, callback.bind(null, userCallback));
  14622. },
  14623.  
  14624.  
  14625. forcePseudoState: function(nodeId, forcedPseudoClasses, userCallback)
  14626. {
  14627. CSSAgent.forcePseudoState(nodeId, forcedPseudoClasses || [], userCallback);
  14628. },
  14629.  
  14630.  
  14631. getNamedFlowCollectionAsync: function(documentNodeId, userCallback)
  14632. {
  14633. var namedFlowCollection = this._namedFlowCollections[documentNodeId];
  14634. if (namedFlowCollection) {
  14635. userCallback(namedFlowCollection);
  14636. return;
  14637. }
  14638.  
  14639.  
  14640. function callback(userCallback, error, namedFlowPayload)
  14641. {
  14642. if (error || !namedFlowPayload)
  14643. userCallback(null);
  14644. else {
  14645. var namedFlowCollection = new WebInspector.NamedFlowCollection(namedFlowPayload);
  14646. this._namedFlowCollections[documentNodeId] = namedFlowCollection;
  14647. userCallback(namedFlowCollection);
  14648. }
  14649. }
  14650.  
  14651. CSSAgent.getNamedFlowCollection(documentNodeId, callback.bind(this, userCallback));
  14652. },
  14653.  
  14654.  
  14655. getFlowByNameAsync: function(documentNodeId, flowName, userCallback)
  14656. {
  14657. var namedFlowCollection = this._namedFlowCollections[documentNodeId];
  14658. if (namedFlowCollection) {
  14659. userCallback(namedFlowCollection.flowByName(flowName));
  14660. return;
  14661. }
  14662.  
  14663.  
  14664. function callback(userCallback, namedFlowCollection)
  14665. {
  14666. if (!namedFlowCollection)
  14667. userCallback(null);
  14668. else
  14669. userCallback(namedFlowCollection.flowByName(flowName));
  14670. }
  14671.  
  14672. this.getNamedFlowCollectionAsync(documentNodeId, callback.bind(this, userCallback));
  14673. },
  14674.  
  14675.  
  14676. setRuleSelector: function(ruleId, nodeId, newSelector, successCallback, failureCallback)
  14677. {
  14678.  
  14679. function checkAffectsCallback(nodeId, successCallback, rulePayload, selectedNodeIds)
  14680. {
  14681. if (!selectedNodeIds)
  14682. return;
  14683. var doesAffectSelectedNode = (selectedNodeIds.indexOf(nodeId) >= 0);
  14684. var rule = WebInspector.CSSRule.parsePayload(rulePayload);
  14685. successCallback(rule, doesAffectSelectedNode);
  14686. }
  14687.  
  14688.  
  14689. function callback(nodeId, successCallback, failureCallback, newSelector, error, rulePayload)
  14690. {
  14691. this._pendingCommandsMajorState.pop();
  14692. if (error)
  14693. failureCallback();
  14694. else {
  14695. WebInspector.domAgent.markUndoableState();
  14696. var ownerDocumentId = this._ownerDocumentId(nodeId);
  14697. if (ownerDocumentId)
  14698. WebInspector.domAgent.querySelectorAll(ownerDocumentId, newSelector, checkAffectsCallback.bind(this, nodeId, successCallback, rulePayload));
  14699. else
  14700. failureCallback();
  14701. }
  14702. }
  14703.  
  14704. this._pendingCommandsMajorState.push(true);
  14705. CSSAgent.setRuleSelector(ruleId, newSelector, callback.bind(this, nodeId, successCallback, failureCallback, newSelector));
  14706. },
  14707.  
  14708.  
  14709. addRule: function(nodeId, selector, successCallback, failureCallback)
  14710. {
  14711.  
  14712. function checkAffectsCallback(nodeId, successCallback, rulePayload, selectedNodeIds)
  14713. {
  14714. if (!selectedNodeIds)
  14715. return;
  14716.  
  14717. var doesAffectSelectedNode = (selectedNodeIds.indexOf(nodeId) >= 0);
  14718. var rule = WebInspector.CSSRule.parsePayload(rulePayload);
  14719. successCallback(rule, doesAffectSelectedNode);
  14720. }
  14721.  
  14722.  
  14723. function callback(successCallback, failureCallback, selector, error, rulePayload)
  14724. {
  14725. this._pendingCommandsMajorState.pop();
  14726. if (error) {
  14727.  
  14728. failureCallback();
  14729. } else {
  14730. WebInspector.domAgent.markUndoableState();
  14731. var ownerDocumentId = this._ownerDocumentId(nodeId);
  14732. if (ownerDocumentId)
  14733. WebInspector.domAgent.querySelectorAll(ownerDocumentId, selector, checkAffectsCallback.bind(this, nodeId, successCallback, rulePayload));
  14734. else
  14735. failureCallback();
  14736. }
  14737. }
  14738.  
  14739. this._pendingCommandsMajorState.push(true);
  14740. CSSAgent.addRule(nodeId, selector, callback.bind(this, successCallback, failureCallback, selector));
  14741. },
  14742.  
  14743. mediaQueryResultChanged: function()
  14744. {
  14745. this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.MediaQueryResultChanged);
  14746. },
  14747.  
  14748.  
  14749. _ownerDocumentId: function(nodeId)
  14750. {
  14751. var node = WebInspector.domAgent.nodeForId(nodeId);
  14752. if (!node)
  14753. return null;
  14754. return node.ownerDocument ? node.ownerDocument.id : null;
  14755. },
  14756.  
  14757.  
  14758. _fireStyleSheetChanged: function(styleSheetId)
  14759. {
  14760. if (!this._pendingCommandsMajorState.length)
  14761. return;
  14762.  
  14763. var majorChange = this._pendingCommandsMajorState[this._pendingCommandsMajorState.length - 1];
  14764.  
  14765. if (!majorChange || !styleSheetId || !this.hasEventListeners(WebInspector.CSSStyleModel.Events.StyleSheetChanged))
  14766. return;
  14767.  
  14768. this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.StyleSheetChanged, { styleSheetId: styleSheetId, majorChange: majorChange });
  14769. },
  14770.  
  14771.  
  14772. _namedFlowCreated: function(namedFlowPayload)
  14773. {
  14774. var namedFlow = WebInspector.NamedFlow.parsePayload(namedFlowPayload);
  14775. var namedFlowCollection = this._namedFlowCollections[namedFlow.documentNodeId];
  14776.  
  14777. if (!namedFlowCollection)
  14778. return;
  14779.  
  14780. namedFlowCollection._appendNamedFlow(namedFlow);
  14781. this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.NamedFlowCreated, namedFlow);
  14782. },
  14783.  
  14784.  
  14785. _namedFlowRemoved: function(documentNodeId, flowName)
  14786. {
  14787. var namedFlowCollection = this._namedFlowCollections[documentNodeId];
  14788.  
  14789. if (!namedFlowCollection)
  14790. return;
  14791.  
  14792. namedFlowCollection._removeNamedFlow(flowName);
  14793. this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.NamedFlowRemoved, { documentNodeId: documentNodeId, flowName: flowName });
  14794. },
  14795.  
  14796.  
  14797. _regionLayoutUpdated: function(namedFlowPayload)
  14798. {
  14799. var namedFlow = WebInspector.NamedFlow.parsePayload(namedFlowPayload);
  14800. var namedFlowCollection = this._namedFlowCollections[namedFlow.documentNodeId];
  14801.  
  14802. if (!namedFlowCollection)
  14803. return;
  14804.  
  14805. namedFlowCollection._appendNamedFlow(namedFlow);
  14806. this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.RegionLayoutUpdated, namedFlow);
  14807. },
  14808.  
  14809.  
  14810. setStyleSheetText: function(styleSheetId, newText, majorChange, userCallback)
  14811. {
  14812. function callback(error)
  14813. {
  14814. this._pendingCommandsMajorState.pop();
  14815. if (!error && majorChange)
  14816. WebInspector.domAgent.markUndoableState();
  14817.  
  14818. if (!error && userCallback)
  14819. userCallback(error);
  14820. }
  14821. this._pendingCommandsMajorState.push(majorChange);
  14822. CSSAgent.setStyleSheetText(styleSheetId, newText, callback.bind(this));
  14823. },
  14824.  
  14825. _undoRedoRequested: function()
  14826. {
  14827. this._pendingCommandsMajorState.push(true);
  14828. },
  14829.  
  14830. _undoRedoCompleted: function()
  14831. {
  14832. this._pendingCommandsMajorState.pop();
  14833. },
  14834.  
  14835.  
  14836. getViaInspectorResourceForRule: function(rule, callback)
  14837. {
  14838. if (!rule.id) {
  14839. callback(null);
  14840. return;
  14841. }
  14842. this._resourceBinding._requestViaInspectorResource(rule.id.styleSheetId, callback);
  14843. },
  14844.  
  14845.  
  14846. resourceBinding: function()
  14847. {
  14848. return this._resourceBinding;
  14849. },
  14850.  
  14851.  
  14852. setSourceMapping: function(url, sourceMapping)
  14853. {
  14854. this._sourceMappings[url] = sourceMapping;
  14855. this._updateLocations();
  14856. },
  14857.  
  14858. resetSourceMappings: function()
  14859. {
  14860. this._sourceMappings = {};
  14861. },
  14862.  
  14863. _resetNamedFlowCollections: function()
  14864. {
  14865. this._namedFlowCollections = {};
  14866. },
  14867.  
  14868. _updateLocations: function()
  14869. {
  14870. for (var i = 0; i < this._locations.length; ++i)
  14871. this._locations[i].update();
  14872. },
  14873.  
  14874.  
  14875. createLiveLocation: function(cssRule, updateDelegate)
  14876. {
  14877. if (!cssRule._rawLocation)
  14878. return null;
  14879. var location = new WebInspector.CSSStyleModel.LiveLocation(cssRule._rawLocation, updateDelegate);
  14880. if (!location.uiLocation())
  14881. return null;
  14882. this._locations.push(location);
  14883. location.update();
  14884. return location;
  14885. },
  14886.  
  14887.  
  14888. _rawLocationToUILocation: function(rawLocation)
  14889. {
  14890. var sourceMapping = this._sourceMappings[rawLocation.url];
  14891. return sourceMapping ? sourceMapping.rawLocationToUILocation(rawLocation) : null;
  14892. },
  14893.  
  14894.  
  14895. toggleInlineVisibility: function(nodeId)
  14896. {
  14897.  
  14898. function callback(inlineStyles)
  14899. {
  14900. var visibility = inlineStyles.getLiveProperty("visibility");
  14901. if (visibility) {
  14902. if (visibility.value === "hidden")
  14903. visibility.setText("", false, true);
  14904. else
  14905. visibility.setValue("hidden", false, true);
  14906. } else
  14907. inlineStyles.appendProperty("visibility", "hidden");
  14908. }
  14909.  
  14910. this.getInlineStylesAsync(nodeId, callback.bind(this));
  14911. },
  14912.  
  14913. __proto__: WebInspector.Object.prototype
  14914. }
  14915.  
  14916.  
  14917. WebInspector.CSSStyleModel.LiveLocation = function(rawLocation, updateDelegate)
  14918. {
  14919. WebInspector.LiveLocation.call(this, rawLocation, updateDelegate);
  14920. }
  14921.  
  14922. WebInspector.CSSStyleModel.LiveLocation.prototype = {
  14923.  
  14924. uiLocation: function()
  14925. {
  14926. var cssLocation =   (this.rawLocation());
  14927. return WebInspector.cssModel._rawLocationToUILocation(cssLocation);
  14928. },
  14929.  
  14930. dispose: function()
  14931. {
  14932. WebInspector.LiveLocation.prototype.dispose.call(this);
  14933. var locations = WebInspector.cssModel._locations;
  14934. if (locations)
  14935. locations.remove(this);
  14936. },
  14937.  
  14938. __proto__: WebInspector.LiveLocation.prototype
  14939. }
  14940.  
  14941.  
  14942. WebInspector.CSSLocation = function(url, lineNumber)
  14943. {
  14944. this.url = url;
  14945. this.lineNumber = lineNumber;
  14946. }
  14947.  
  14948.  
  14949. WebInspector.CSSStyleDeclaration = function(payload)
  14950. {
  14951. this.id = payload.styleId;
  14952. this.width = payload.width;
  14953. this.height = payload.height;
  14954. this.range = payload.range;
  14955. this._shorthandValues = WebInspector.CSSStyleDeclaration.buildShorthandValueMap(payload.shorthandEntries);
  14956. this._livePropertyMap = {}; 
  14957. this._allProperties = []; 
  14958. this.__disabledProperties = {}; 
  14959. var payloadPropertyCount = payload.cssProperties.length;
  14960.  
  14961. var propertyIndex = 0;
  14962. for (var i = 0; i < payloadPropertyCount; ++i) {
  14963. var property = WebInspector.CSSProperty.parsePayload(this, i, payload.cssProperties[i]);
  14964. this._allProperties.push(property);
  14965. if (property.disabled)
  14966. this.__disabledProperties[i] = property;
  14967. if (!property.active && !property.styleBased)
  14968. continue;
  14969. var name = property.name;
  14970. this[propertyIndex] = name;
  14971. this._livePropertyMap[name] = property;
  14972. ++propertyIndex;
  14973. }
  14974. this.length = propertyIndex;
  14975. if ("cssText" in payload)
  14976. this.cssText = payload.cssText;
  14977. }
  14978.  
  14979.  
  14980. WebInspector.CSSStyleDeclaration.buildShorthandValueMap = function(shorthandEntries)
  14981. {
  14982. var result = {};
  14983. for (var i = 0; i < shorthandEntries.length; ++i)
  14984. result[shorthandEntries[i].name] = shorthandEntries[i].value;
  14985. return result;
  14986. }
  14987.  
  14988.  
  14989. WebInspector.CSSStyleDeclaration.parsePayload = function(payload)
  14990. {
  14991. return new WebInspector.CSSStyleDeclaration(payload);
  14992. }
  14993.  
  14994.  
  14995. WebInspector.CSSStyleDeclaration.parseComputedStylePayload = function(payload)
  14996. {
  14997. var newPayload =   ({ cssProperties: [], shorthandEntries: [], width: "", height: "" });
  14998. if (payload)
  14999. newPayload.cssProperties = payload;
  15000.  
  15001. return new WebInspector.CSSStyleDeclaration(newPayload);
  15002. }
  15003.  
  15004. WebInspector.CSSStyleDeclaration.prototype = {
  15005. get allProperties()
  15006. {
  15007. return this._allProperties;
  15008. },
  15009.  
  15010.  
  15011. getLiveProperty: function(name)
  15012. {
  15013. return this._livePropertyMap[name];
  15014. },
  15015.  
  15016.  
  15017. getPropertyValue: function(name)
  15018. {
  15019. var property = this._livePropertyMap[name];
  15020. return property ? property.value : "";
  15021. },
  15022.  
  15023.  
  15024. getPropertyPriority: function(name)
  15025. {
  15026. var property = this._livePropertyMap[name];
  15027. return property ? property.priority : "";
  15028. },
  15029.  
  15030.  
  15031. isPropertyImplicit: function(name)
  15032. {
  15033. var property = this._livePropertyMap[name];
  15034. return property ? property.implicit : "";
  15035. },
  15036.  
  15037.  
  15038. longhandProperties: function(name)
  15039. {
  15040. var longhands = WebInspector.CSSCompletions.cssPropertiesMetainfo.longhands(name);
  15041. var result = [];
  15042. for (var i = 0; longhands && i < longhands.length; ++i) {
  15043. var property = this._livePropertyMap[longhands[i]];
  15044. if (property)
  15045. result.push(property);
  15046. }
  15047. return result;
  15048. },
  15049.  
  15050.  
  15051. shorthandValue: function(shorthandProperty)
  15052. {
  15053. return this._shorthandValues[shorthandProperty];
  15054. },
  15055.  
  15056.  
  15057. propertyAt: function(index)
  15058. {
  15059. return (index < this.allProperties.length) ? this.allProperties[index] : null;
  15060. },
  15061.  
  15062.  
  15063. pastLastSourcePropertyIndex: function()
  15064. {
  15065. for (var i = this.allProperties.length - 1; i >= 0; --i) {
  15066. var property = this.allProperties[i];
  15067. if (property.active || property.disabled)
  15068. return i + 1;
  15069. }
  15070. return 0;
  15071. },
  15072.  
  15073.  
  15074. newBlankProperty: function(index)
  15075. {
  15076. index = (typeof index === "undefined") ? this.pastLastSourcePropertyIndex() : index;
  15077. return new WebInspector.CSSProperty(this, index, "", "", "", "active", true, false, "");
  15078. },
  15079.  
  15080.  
  15081. insertPropertyAt: function(index, name, value, userCallback)
  15082. {
  15083.  
  15084. function callback(error, payload)
  15085. {
  15086. WebInspector.cssModel._pendingCommandsMajorState.pop();
  15087. if (!userCallback)
  15088. return;
  15089.  
  15090. if (error) {
  15091. console.error(error);
  15092. userCallback(null);
  15093. } else {
  15094. userCallback(WebInspector.CSSStyleDeclaration.parsePayload(payload));
  15095. }
  15096. }
  15097.  
  15098. if (!this.id)
  15099. throw "No style id";
  15100.  
  15101. WebInspector.cssModel._pendingCommandsMajorState.push(true);
  15102. CSSAgent.setPropertyText(this.id, index, name + ": " + value + ";", false, callback.bind(this));
  15103. },
  15104.  
  15105.  
  15106. appendProperty: function(name, value, userCallback)
  15107. {
  15108. this.insertPropertyAt(this.allProperties.length, name, value, userCallback);
  15109. }
  15110. }
  15111.  
  15112.  
  15113. WebInspector.CSSRule = function(payload, matchingSelectors)
  15114. {
  15115. this.id = payload.ruleId;
  15116. if (matchingSelectors)
  15117. this.matchingSelectors = matchingSelectors;
  15118. this.selectors = payload.selectorList.selectors;
  15119. this.selectorText = this.selectors.join(", ");
  15120. this.selectorRange = payload.selectorList.range;
  15121. this.sourceLine = payload.sourceLine;
  15122. this.sourceURL = payload.sourceURL;
  15123. if (payload.sourceURL)
  15124. this._rawLocation = new WebInspector.CSSLocation(payload.sourceURL, payload.sourceLine);
  15125. this.origin = payload.origin;
  15126. this.style = WebInspector.CSSStyleDeclaration.parsePayload(payload.style);
  15127. this.style.parentRule = this;
  15128. if (payload.media)
  15129. this.media = WebInspector.CSSMedia.parseMediaArrayPayload(payload.media);
  15130. }
  15131.  
  15132.  
  15133. WebInspector.CSSRule.parsePayload = function(payload, matchingIndices)
  15134. {
  15135. return new WebInspector.CSSRule(payload, matchingIndices);
  15136. }
  15137.  
  15138. WebInspector.CSSRule.prototype = {
  15139. get isUserAgent()
  15140. {
  15141. return this.origin === "user-agent";
  15142. },
  15143.  
  15144. get isUser()
  15145. {
  15146. return this.origin === "user";
  15147. },
  15148.  
  15149. get isViaInspector()
  15150. {
  15151. return this.origin === "inspector";
  15152. },
  15153.  
  15154. get isRegular()
  15155. {
  15156. return this.origin === "regular";
  15157. }
  15158. }
  15159.  
  15160.  
  15161. WebInspector.CSSProperty = function(ownerStyle, index, name, value, priority, status, parsedOk, implicit, text)
  15162. {
  15163. this.ownerStyle = ownerStyle;
  15164. this.index = index;
  15165. this.name = name;
  15166. this.value = value;
  15167. this.priority = priority;
  15168. this.status = status;
  15169. this.parsedOk = parsedOk;
  15170. this.implicit = implicit;
  15171. this.text = text;
  15172. }
  15173.  
  15174.  
  15175. WebInspector.CSSProperty.parsePayload = function(ownerStyle, index, payload)
  15176. {
  15177.  
  15178.  
  15179.  
  15180.  
  15181.  
  15182. var result = new WebInspector.CSSProperty(
  15183. ownerStyle, index, payload.name, payload.value, payload.priority || "", payload.status || "style", ("parsedOk" in payload) ? !!payload.parsedOk : true, !!payload.implicit, payload.text);
  15184. return result;
  15185. }
  15186.  
  15187. WebInspector.CSSProperty.prototype = {
  15188. get propertyText()
  15189. {
  15190. if (this.text !== undefined)
  15191. return this.text;
  15192.  
  15193. if (this.name === "")
  15194. return "";
  15195. return this.name + ": " + this.value + (this.priority ? " !" + this.priority : "") + ";";
  15196. },
  15197.  
  15198. get isLive()
  15199. {
  15200. return this.active || this.styleBased;
  15201. },
  15202.  
  15203. get active()
  15204. {
  15205. return this.status === "active";
  15206. },
  15207.  
  15208. get styleBased()
  15209. {
  15210. return this.status === "style";
  15211. },
  15212.  
  15213. get inactive()
  15214. {
  15215. return this.status === "inactive";
  15216. },
  15217.  
  15218. get disabled()
  15219. {
  15220. return this.status === "disabled";
  15221. },
  15222.  
  15223.  
  15224. setText: function(propertyText, majorChange, overwrite, userCallback)
  15225. {
  15226.  
  15227. function enabledCallback(style)
  15228. {
  15229. if (userCallback)
  15230. userCallback(style);
  15231. }
  15232.  
  15233.  
  15234. function callback(error, stylePayload)
  15235. {
  15236. WebInspector.cssModel._pendingCommandsMajorState.pop();
  15237. if (!error) {
  15238. if (majorChange)
  15239. WebInspector.domAgent.markUndoableState();
  15240. this.text = propertyText;
  15241. var style = WebInspector.CSSStyleDeclaration.parsePayload(stylePayload);
  15242. var newProperty = style.allProperties[this.index];
  15243.  
  15244. if (newProperty && this.disabled && !propertyText.match(/^\s*$/)) {
  15245. newProperty.setDisabled(false, enabledCallback);
  15246. return;
  15247. }
  15248.  
  15249. if (userCallback)
  15250. userCallback(style);
  15251. } else {
  15252. if (userCallback)
  15253. userCallback(null);
  15254. }
  15255. }
  15256.  
  15257. if (!this.ownerStyle)
  15258. throw "No ownerStyle for property";
  15259.  
  15260. if (!this.ownerStyle.id)
  15261. throw "No owner style id";
  15262.  
  15263.  
  15264. WebInspector.cssModel._pendingCommandsMajorState.push(majorChange);
  15265. CSSAgent.setPropertyText(this.ownerStyle.id, this.index, propertyText, overwrite, callback.bind(this));
  15266. },
  15267.  
  15268.  
  15269. setValue: function(newValue, majorChange, overwrite, userCallback)
  15270. {
  15271. var text = this.name + ": " + newValue + (this.priority ? " !" + this.priority : "") + ";"
  15272. this.setText(text, majorChange, overwrite, userCallback);
  15273. },
  15274.  
  15275.  
  15276. setDisabled: function(disabled, userCallback)
  15277. {
  15278. if (!this.ownerStyle && userCallback)
  15279. userCallback(null);
  15280. if (disabled === this.disabled && userCallback)
  15281. userCallback(this.ownerStyle);
  15282.  
  15283.  
  15284. function callback(error, stylePayload)
  15285. {
  15286. WebInspector.cssModel._pendingCommandsMajorState.pop();
  15287. if (error) {
  15288. if (userCallback)
  15289. userCallback(null);
  15290. return;
  15291. }
  15292. WebInspector.domAgent.markUndoableState();
  15293. if (userCallback) {
  15294. var style = WebInspector.CSSStyleDeclaration.parsePayload(stylePayload);
  15295. userCallback(style);
  15296. }
  15297. }
  15298.  
  15299. if (!this.ownerStyle.id)
  15300. throw "No owner style id";
  15301.  
  15302. WebInspector.cssModel._pendingCommandsMajorState.push(false);
  15303. CSSAgent.toggleProperty(this.ownerStyle.id, this.index, disabled, callback.bind(this));
  15304. }
  15305. }
  15306.  
  15307.  
  15308. WebInspector.CSSMedia = function(payload)
  15309. {
  15310. this.text = payload.text;
  15311. this.source = payload.source;
  15312. this.sourceURL = payload.sourceURL || "";
  15313. this.sourceLine = typeof payload.sourceLine === "undefined" || this.source === "linkedSheet" ? -1 : payload.sourceLine;
  15314. }
  15315.  
  15316. WebInspector.CSSMedia.Source = {
  15317. LINKED_SHEET: "linkedSheet",
  15318. INLINE_SHEET: "inlineSheet",
  15319. MEDIA_RULE: "mediaRule",
  15320. IMPORT_RULE: "importRule"
  15321. };
  15322.  
  15323.  
  15324. WebInspector.CSSMedia.parsePayload = function(payload)
  15325. {
  15326. return new WebInspector.CSSMedia(payload);
  15327. }
  15328.  
  15329.  
  15330. WebInspector.CSSMedia.parseMediaArrayPayload = function(payload)
  15331. {
  15332. var result = [];
  15333. for (var i = 0; i < payload.length; ++i)
  15334. result.push(WebInspector.CSSMedia.parsePayload(payload[i]));
  15335. return result;
  15336. }
  15337.  
  15338.  
  15339. WebInspector.CSSStyleSheet = function(payload)
  15340. {
  15341. this.id = payload.styleSheetId;
  15342. this.rules = [];
  15343. this.styles = {};
  15344. for (var i = 0; i < payload.rules.length; ++i) {
  15345. var rule = WebInspector.CSSRule.parsePayload(payload.rules[i]);
  15346. this.rules.push(rule);
  15347. if (rule.style)
  15348. this.styles[rule.style.id] = rule.style;
  15349. }
  15350. if ("text" in payload)
  15351. this._text = payload.text;
  15352. }
  15353.  
  15354.  
  15355. WebInspector.CSSStyleSheet.createForId = function(styleSheetId, userCallback)
  15356. {
  15357.  
  15358. function callback(error, styleSheetPayload)
  15359. {
  15360. if (error)
  15361. userCallback(null);
  15362. else
  15363. userCallback(new WebInspector.CSSStyleSheet(styleSheetPayload));
  15364. }
  15365. CSSAgent.getStyleSheet(styleSheetId, callback.bind(this));
  15366. }
  15367.  
  15368. WebInspector.CSSStyleSheet.prototype = {
  15369.  
  15370. getText: function()
  15371. {
  15372. return this._text;
  15373. },
  15374.  
  15375.  
  15376. setText: function(newText, majorChange, userCallback)
  15377. {
  15378.  
  15379. function callback(error)
  15380. {
  15381. if (!error)
  15382. WebInspector.domAgent.markUndoableState();
  15383.  
  15384. WebInspector.cssModel._pendingCommandsMajorState.pop();
  15385. if (userCallback)
  15386. userCallback(error);
  15387. }
  15388.  
  15389. WebInspector.cssModel._pendingCommandsMajorState.push(majorChange);
  15390. CSSAgent.setStyleSheetText(this.id, newText, callback.bind(this));
  15391. }
  15392. }
  15393.  
  15394.  
  15395. WebInspector.CSSStyleModelResourceBinding = function()
  15396. {
  15397. this._frameAndURLToStyleSheetId = {};
  15398. this._styleSheetIdToHeader = {};
  15399. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.InspectedURLChanged, this._inspectedURLChanged, this);
  15400. }
  15401.  
  15402. WebInspector.CSSStyleModelResourceBinding.prototype = {
  15403.  
  15404. requestStyleSheetIdForResource: function(resource, callback)
  15405. {
  15406. function innerCallback()
  15407. {
  15408. callback(this._styleSheetIdForResource(resource));
  15409. }
  15410.  
  15411. if (this._styleSheetIdForResource(resource))
  15412. innerCallback.call(this);
  15413. else
  15414. this._loadStyleSheetHeaders(innerCallback.bind(this));
  15415. },
  15416.  
  15417.  
  15418. requestResourceURLForStyleSheetId: function(styleSheetId, callback)
  15419. {
  15420. function innerCallback()
  15421. {
  15422. var header = this._styleSheetIdToHeader[styleSheetId];
  15423. if (!header) {
  15424. callback(null);
  15425. return;
  15426. }
  15427.  
  15428. var frame = WebInspector.resourceTreeModel.frameForId(header.frameId);
  15429. if (!frame) {
  15430. callback(null);
  15431. return;
  15432. }
  15433.  
  15434. var styleSheetURL = header.origin === "inspector" ? this._viaInspectorResourceURL(header.sourceURL) : header.sourceURL;
  15435. callback(styleSheetURL);
  15436. }
  15437.  
  15438. if (this._styleSheetIdToHeader[styleSheetId])
  15439. innerCallback.call(this);
  15440. else
  15441. this._loadStyleSheetHeaders(innerCallback.bind(this));
  15442. },
  15443.  
  15444.  
  15445. _styleSheetIdForResource: function(resource)
  15446. {
  15447. return this._frameAndURLToStyleSheetId[resource.frameId + ":" + resource.url];
  15448. },
  15449.  
  15450.  
  15451. _inspectedURLChanged: function(event)
  15452. {
  15453.  
  15454. this._frameAndURLToStyleSheetId = {};
  15455. this._styleSheetIdToHeader = {};
  15456. },
  15457.  
  15458.  
  15459. _loadStyleSheetHeaders: function(callback)
  15460. {
  15461.  
  15462. function didGetAllStyleSheets(error, infos)
  15463. {
  15464. if (error) {
  15465. callback(error);
  15466. return;
  15467. }
  15468.  
  15469. for (var i = 0; i < infos.length; ++i) {
  15470. var info = infos[i];
  15471. if (info.origin === "inspector") {
  15472. this._getOrCreateInspectorResource(info);
  15473. continue;
  15474. }
  15475. this._frameAndURLToStyleSheetId[info.frameId + ":" + info.sourceURL] = info.styleSheetId;
  15476. this._styleSheetIdToHeader[info.styleSheetId] = info;
  15477. }
  15478. callback(null);
  15479. }
  15480. CSSAgent.getAllStyleSheets(didGetAllStyleSheets.bind(this));
  15481. },
  15482.  
  15483.  
  15484. _requestViaInspectorResource: function(styleSheetId, callback)
  15485. {
  15486. var header = this._styleSheetIdToHeader[styleSheetId];
  15487. if (header) {
  15488. callback(this._getOrCreateInspectorResource(header));
  15489. return;
  15490. }
  15491.  
  15492. function headersLoaded()
  15493. {
  15494. var header = this._styleSheetIdToHeader[styleSheetId];
  15495. if (header)
  15496. callback(this._getOrCreateInspectorResource(header));
  15497. else
  15498. callback(null);
  15499. }
  15500. this._loadStyleSheetHeaders(headersLoaded.bind(this));
  15501. },
  15502.  
  15503.  
  15504. _getOrCreateInspectorResource: function(header)
  15505. {
  15506. var frame = WebInspector.resourceTreeModel.frameForId(header.frameId);
  15507. if (!frame)
  15508. return null;
  15509.  
  15510. var viaInspectorURL = this._viaInspectorResourceURL(header.sourceURL);    
  15511. var inspectorResource = frame.resourceForURL(viaInspectorURL);
  15512. if (inspectorResource)
  15513. return inspectorResource;
  15514.  
  15515. var resource = frame.resourceForURL(header.sourceURL);
  15516. if (!resource)
  15517. return null;
  15518.  
  15519. this._frameAndURLToStyleSheetId[header.frameId + ":" + viaInspectorURL] = header.styleSheetId;
  15520. this._styleSheetIdToHeader[header.styleSheetId] = header;
  15521. inspectorResource = new WebInspector.Resource(null, viaInspectorURL, resource.documentURL, resource.frameId, resource.loaderId, WebInspector.resourceTypes.Stylesheet, "text/css", true);
  15522.  
  15523. function overrideRequestContent(callback)
  15524. {
  15525. function callbackWrapper(error, content)
  15526. {
  15527. callback(error ? "" : content, false, "text/css");
  15528. }
  15529. CSSAgent.getStyleSheetText(header.styleSheetId, callbackWrapper);
  15530. }
  15531. inspectorResource.requestContent = overrideRequestContent;
  15532. frame.addResource(inspectorResource);
  15533. return inspectorResource;
  15534. },
  15535.  
  15536.  
  15537. _viaInspectorResourceURL: function(documentURL)
  15538. {
  15539. var parsedURL = new WebInspector.ParsedURL(documentURL);
  15540. var fakeURL = "inspector://" + parsedURL.host + parsedURL.folderPathComponents;
  15541. if (!fakeURL.endsWith("/"))
  15542. fakeURL += "/";
  15543. fakeURL += "inspector-stylesheet";
  15544. return fakeURL;
  15545. }
  15546. }
  15547.  
  15548.  
  15549. WebInspector.CSSDispatcher = function(cssModel)
  15550. {
  15551. this._cssModel = cssModel;
  15552. }
  15553.  
  15554. WebInspector.CSSDispatcher.prototype = {
  15555. mediaQueryResultChanged: function()
  15556. {
  15557. this._cssModel.mediaQueryResultChanged();
  15558. },
  15559.  
  15560.  
  15561. styleSheetChanged: function(styleSheetId)
  15562. {
  15563. this._cssModel._fireStyleSheetChanged(styleSheetId);
  15564. },
  15565.  
  15566.  
  15567. namedFlowCreated: function(namedFlowPayload)
  15568. {
  15569. this._cssModel._namedFlowCreated(namedFlowPayload);
  15570. },
  15571.  
  15572.  
  15573. namedFlowRemoved: function(documentNodeId, flowName)
  15574. {
  15575. this._cssModel._namedFlowRemoved(documentNodeId, flowName);
  15576. },
  15577.  
  15578.  
  15579. regionLayoutUpdated: function(namedFlowPayload)
  15580. {
  15581. this._cssModel._regionLayoutUpdated(namedFlowPayload);
  15582. }
  15583. }
  15584.  
  15585.  
  15586. WebInspector.NamedFlow = function(payload)
  15587. {
  15588. this.documentNodeId = payload.documentNodeId;
  15589. this.name = payload.name;
  15590. this.overset = payload.overset;
  15591. this.content = payload.content;
  15592. this.regions = payload.regions;
  15593. }
  15594.  
  15595.  
  15596. WebInspector.NamedFlow.parsePayload = function(payload)
  15597. {
  15598. return new WebInspector.NamedFlow(payload);
  15599. }
  15600.  
  15601.  
  15602. WebInspector.NamedFlowCollection = function(payload)
  15603. {
  15604.  
  15605. this.namedFlowMap = {};
  15606.  
  15607. for (var i = 0; i < payload.length; ++i) {
  15608. var namedFlow = WebInspector.NamedFlow.parsePayload(payload[i]);
  15609. this.namedFlowMap[namedFlow.name] = namedFlow;
  15610. }
  15611. }
  15612.  
  15613. WebInspector.NamedFlowCollection.prototype = {
  15614.  
  15615. _appendNamedFlow: function(namedFlow)
  15616. {
  15617. this.namedFlowMap[namedFlow.name] = namedFlow;
  15618. },
  15619.  
  15620.  
  15621. _removeNamedFlow: function(flowName)
  15622. {
  15623. delete this.namedFlowMap[flowName];
  15624. },
  15625.  
  15626.  
  15627. flowByName: function(flowName)
  15628. {
  15629. var namedFlow = this.namedFlowMap[flowName];
  15630.  
  15631. if (!namedFlow)
  15632. return null;
  15633. return namedFlow;
  15634. }
  15635. }
  15636.  
  15637. WebInspector.cssModel = null;
  15638.  
  15639.  
  15640.  
  15641.  
  15642.  
  15643.  
  15644. WebInspector.NetworkManager = function()
  15645. {
  15646. WebInspector.Object.call(this);
  15647. this._dispatcher = new WebInspector.NetworkDispatcher(this);
  15648. if (WebInspector.settings.cacheDisabled.get())
  15649. NetworkAgent.setCacheDisabled(true);
  15650.  
  15651. NetworkAgent.enable();
  15652.  
  15653. WebInspector.settings.cacheDisabled.addChangeListener(this._cacheDisabledSettingChanged, this);
  15654. }
  15655.  
  15656. WebInspector.NetworkManager.EventTypes = {
  15657. RequestStarted: "RequestStarted",
  15658. RequestUpdated: "RequestUpdated",
  15659. RequestFinished: "RequestFinished",
  15660. RequestUpdateDropped: "RequestUpdateDropped"
  15661. }
  15662.  
  15663. WebInspector.NetworkManager._MIMETypes = {
  15664. "text/html":                   {"document": true},
  15665. "text/xml":                    {"document": true},
  15666. "text/plain":                  {"document": true},
  15667. "application/xhtml+xml":       {"document": true},
  15668. "text/css":                    {"stylesheet": true},
  15669. "text/xsl":                    {"stylesheet": true},
  15670. "image/jpg":                   {"image": true},
  15671. "image/jpeg":                  {"image": true},
  15672. "image/pjpeg":                 {"image": true},
  15673. "image/png":                   {"image": true},
  15674. "image/gif":                   {"image": true},
  15675. "image/bmp":                   {"image": true},
  15676. "image/svg+xml":               {"image": true},
  15677. "image/vnd.microsoft.icon":    {"image": true},
  15678. "image/webp":                  {"image": true},
  15679. "image/x-icon":                {"image": true},
  15680. "image/x-xbitmap":             {"image": true},
  15681. "font/ttf":                    {"font": true},
  15682. "font/opentype":               {"font": true},
  15683. "font/woff":                   {"font": true},
  15684. "application/x-font-type1":    {"font": true},
  15685. "application/x-font-ttf":      {"font": true},
  15686. "application/x-font-woff":     {"font": true},
  15687. "application/x-truetype-font": {"font": true},
  15688. "text/javascript":             {"script": true},
  15689. "text/ecmascript":             {"script": true},
  15690. "application/javascript":      {"script": true},
  15691. "application/ecmascript":      {"script": true},
  15692. "application/x-javascript":    {"script": true},
  15693. "application/json":            {"script": true},
  15694. "text/javascript1.1":          {"script": true},
  15695. "text/javascript1.2":          {"script": true},
  15696. "text/javascript1.3":          {"script": true},
  15697. "text/jscript":                {"script": true},
  15698. "text/livescript":             {"script": true},
  15699. }
  15700.  
  15701. WebInspector.NetworkManager.prototype = {
  15702.  
  15703. inflightRequestForURL: function(url)
  15704. {
  15705. return this._dispatcher._inflightRequestsByURL[url];
  15706. },
  15707.  
  15708.  
  15709. _cacheDisabledSettingChanged: function(event)
  15710. {
  15711. var enabled =   (event.data);
  15712. NetworkAgent.setCacheDisabled(enabled);
  15713. },
  15714.  
  15715. __proto__: WebInspector.Object.prototype
  15716. }
  15717.  
  15718.  
  15719. WebInspector.NetworkDispatcher = function(manager)
  15720. {
  15721. this._manager = manager;
  15722. this._inflightRequestsById = {};
  15723. this._inflightRequestsByURL = {};
  15724. InspectorBackend.registerNetworkDispatcher(this);
  15725. }
  15726.  
  15727. WebInspector.NetworkDispatcher.prototype = {
  15728.  
  15729. _headersMapToHeadersArray: function(headersMap)
  15730. {
  15731. var result = [];
  15732. for (var name in headersMap) {
  15733. var values = headersMap[name].split("\n");
  15734. for (var i = 0; i < values.length; ++i)
  15735. result.push({ name: name, value: values[i] });
  15736. }
  15737. return result;
  15738. },
  15739.  
  15740.  
  15741. _updateNetworkRequestWithRequest: function(networkRequest, request)
  15742. {
  15743. networkRequest.requestMethod = request.method;
  15744. networkRequest.requestHeaders = this._headersMapToHeadersArray(request.headers);
  15745. networkRequest.requestFormData = request.postData;
  15746. },
  15747.  
  15748.  
  15749. _updateNetworkRequestWithResponse: function(networkRequest, response)
  15750. {
  15751. if (!response)
  15752. return;
  15753.  
  15754. if (response.url && networkRequest.url !== response.url)
  15755. networkRequest.url = response.url;
  15756. networkRequest.mimeType = response.mimeType;
  15757. networkRequest.statusCode = response.status;
  15758. networkRequest.statusText = response.statusText;
  15759. networkRequest.responseHeaders = this._headersMapToHeadersArray(response.headers);
  15760. if (response.headersText)
  15761. networkRequest.responseHeadersText = response.headersText;
  15762. if (response.requestHeaders)
  15763. networkRequest.requestHeaders = this._headersMapToHeadersArray(response.requestHeaders);
  15764. if (response.requestHeadersText)
  15765. networkRequest.requestHeadersText = response.requestHeadersText;
  15766.  
  15767. networkRequest.connectionReused = response.connectionReused;
  15768. networkRequest.connectionId = response.connectionId;
  15769.  
  15770. if (response.fromDiskCache)
  15771. networkRequest.cached = true;
  15772. else
  15773. networkRequest.timing = response.timing;
  15774.  
  15775. if (!this._mimeTypeIsConsistentWithType(networkRequest)) {
  15776. WebInspector.console.addMessage(WebInspector.ConsoleMessage.create(WebInspector.ConsoleMessage.MessageSource.Network,
  15777. WebInspector.ConsoleMessage.MessageLevel.Warning,
  15778. WebInspector.UIString("Resource interpreted as %s but transferred with MIME type %s: \"%s\".", networkRequest.type.title(), networkRequest.mimeType, networkRequest.url),
  15779. WebInspector.ConsoleMessage.MessageType.Log,
  15780. "",
  15781. 0,
  15782. 1,
  15783. [],
  15784. null,
  15785. networkRequest.requestId));
  15786. }
  15787. },
  15788.  
  15789.  
  15790. _mimeTypeIsConsistentWithType: function(networkRequest)
  15791. {
  15792.  
  15793.  
  15794.  
  15795.  
  15796.  
  15797.  
  15798. if (networkRequest.hasErrorStatusCode() || networkRequest.statusCode === 304 || networkRequest.statusCode === 204)
  15799. return true;
  15800.  
  15801. if (typeof networkRequest.type === "undefined"
  15802. || networkRequest.type === WebInspector.resourceTypes.Other
  15803. || networkRequest.type === WebInspector.resourceTypes.XHR
  15804. || networkRequest.type === WebInspector.resourceTypes.WebSocket)
  15805. return true;
  15806.  
  15807. if (!networkRequest.mimeType)
  15808. return true; 
  15809.  
  15810. if (networkRequest.mimeType in WebInspector.NetworkManager._MIMETypes)
  15811. return networkRequest.type.name() in WebInspector.NetworkManager._MIMETypes[networkRequest.mimeType];
  15812.  
  15813. return false;
  15814. },
  15815.  
  15816.  
  15817. _updateNetworkRequestWithCachedResource: function(networkRequest, cachedResource)
  15818. {
  15819. networkRequest.type = WebInspector.resourceTypes[cachedResource.type];
  15820. networkRequest.resourceSize = cachedResource.bodySize;
  15821. this._updateNetworkRequestWithResponse(networkRequest, cachedResource.response);
  15822. },
  15823.  
  15824.  
  15825. _isNull: function(response)
  15826. {
  15827. if (!response)
  15828. return true;
  15829. return !response.status && !response.mimeType && (!response.headers || !Object.keys(response.headers).length);
  15830. },
  15831.  
  15832.  
  15833. requestWillBeSent: function(requestId, frameId, loaderId, documentURL, request, time, initiator, redirectResponse)
  15834. {
  15835. var networkRequest = this._inflightRequestsById[requestId];
  15836. if (networkRequest) {
  15837.  
  15838. if (!redirectResponse)
  15839. return;
  15840. this.responseReceived(requestId, frameId, loaderId, time, "Other", redirectResponse);
  15841. networkRequest = this._appendRedirect(requestId, time, request.url);
  15842. } else
  15843. networkRequest = this._createNetworkRequest(requestId, frameId, loaderId, request.url, documentURL, initiator);
  15844. networkRequest.hasNetworkData = true;
  15845. this._updateNetworkRequestWithRequest(networkRequest, request);
  15846. networkRequest.startTime = time;
  15847.  
  15848. this._startNetworkRequest(networkRequest);
  15849. },
  15850.  
  15851.  
  15852. requestServedFromCache: function(requestId)
  15853. {
  15854. var networkRequest = this._inflightRequestsById[requestId];
  15855. if (!networkRequest)
  15856. return;
  15857.  
  15858. networkRequest.cached = true;
  15859. },
  15860.  
  15861.  
  15862. responseReceived: function(requestId, frameId, loaderId, time, resourceType, response)
  15863. {
  15864.  
  15865. if (this._isNull(response))
  15866. return;
  15867.  
  15868. var networkRequest = this._inflightRequestsById[requestId];
  15869. if (!networkRequest) {
  15870.  
  15871. var eventData = {};
  15872. eventData.url = response.url;
  15873. eventData.frameId = frameId;
  15874. eventData.loaderId = loaderId;
  15875. eventData.resourceType = resourceType;
  15876. eventData.mimeType = response.mimeType;
  15877. this._manager.dispatchEventToListeners(WebInspector.NetworkManager.EventTypes.RequestUpdateDropped, eventData);
  15878. return;
  15879. }
  15880.  
  15881. networkRequest.responseReceivedTime = time;
  15882. networkRequest.type = WebInspector.resourceTypes[resourceType];
  15883.  
  15884. this._updateNetworkRequestWithResponse(networkRequest, response);
  15885.  
  15886. this._updateNetworkRequest(networkRequest);
  15887. },
  15888.  
  15889.  
  15890. dataReceived: function(requestId, time, dataLength, encodedDataLength)
  15891. {
  15892. var networkRequest = this._inflightRequestsById[requestId];
  15893. if (!networkRequest)
  15894. return;
  15895.  
  15896. networkRequest.resourceSize += dataLength;
  15897. if (encodedDataLength != -1)
  15898. networkRequest.increaseTransferSize(encodedDataLength);
  15899. networkRequest.endTime = time;
  15900.  
  15901. this._updateNetworkRequest(networkRequest);
  15902. },
  15903.  
  15904.  
  15905. loadingFinished: function(requestId, finishTime)
  15906. {
  15907. var networkRequest = this._inflightRequestsById[requestId];
  15908. if (!networkRequest)
  15909. return;
  15910. this._finishNetworkRequest(networkRequest, finishTime);
  15911. },
  15912.  
  15913.  
  15914. loadingFailed: function(requestId, time, localizedDescription, canceled)
  15915. {
  15916. var networkRequest = this._inflightRequestsById[requestId];
  15917. if (!networkRequest)
  15918. return;
  15919.  
  15920. networkRequest.failed = true;
  15921. networkRequest.canceled = canceled;
  15922. networkRequest.localizedFailDescription = localizedDescription;
  15923. this._finishNetworkRequest(networkRequest, time);
  15924. },
  15925.  
  15926.  
  15927. requestServedFromMemoryCache: function(requestId, frameId, loaderId, documentURL, time, initiator, cachedResource)
  15928. {
  15929. var networkRequest = this._createNetworkRequest(requestId, frameId, loaderId, cachedResource.url, documentURL, initiator);
  15930. this._updateNetworkRequestWithCachedResource(networkRequest, cachedResource);
  15931. networkRequest.cached = true;
  15932. networkRequest.requestMethod = "GET";
  15933. this._startNetworkRequest(networkRequest);
  15934. networkRequest.startTime = networkRequest.responseReceivedTime = time;
  15935. this._finishNetworkRequest(networkRequest, time);
  15936. },
  15937.  
  15938.  
  15939. webSocketCreated: function(requestId, requestURL)
  15940. {
  15941. var networkRequest = new WebInspector.NetworkRequest(requestId, requestURL, "", "", "");
  15942. networkRequest.type = WebInspector.resourceTypes.WebSocket;
  15943. this._startNetworkRequest(networkRequest);
  15944. },
  15945.  
  15946.  
  15947. webSocketWillSendHandshakeRequest: function(requestId, time, request)
  15948. {
  15949. var networkRequest = this._inflightRequestsById[requestId];
  15950. if (!networkRequest)
  15951. return;
  15952.  
  15953. networkRequest.requestMethod = "GET";
  15954. networkRequest.requestHeaders = this._headersMapToHeadersArray(request.headers);
  15955. networkRequest.webSocketRequestKey3 = request.requestKey3;
  15956. networkRequest.startTime = time;
  15957.  
  15958. this._updateNetworkRequest(networkRequest);
  15959. },
  15960.  
  15961.  
  15962. webSocketHandshakeResponseReceived: function(requestId, time, response)
  15963. {
  15964. var networkRequest = this._inflightRequestsById[requestId];
  15965. if (!networkRequest)
  15966. return;
  15967.  
  15968. networkRequest.statusCode = response.status;
  15969. networkRequest.statusText = response.statusText;
  15970. networkRequest.responseHeaders = this._headersMapToHeadersArray(response.headers);
  15971. networkRequest.webSocketChallengeResponse = response.challengeResponse;
  15972. networkRequest.responseReceivedTime = time;
  15973.  
  15974. this._updateNetworkRequest(networkRequest);
  15975. },
  15976.  
  15977.  
  15978. webSocketFrameReceived: function(requestId, time, response)
  15979. {
  15980. var networkRequest = this._inflightRequestsById[requestId];
  15981. if (!networkRequest)
  15982. return;
  15983.  
  15984. networkRequest.addFrame(response, time);
  15985. networkRequest.responseReceivedTime = time;
  15986.  
  15987. this._updateNetworkRequest(networkRequest);
  15988. },
  15989.  
  15990.  
  15991. webSocketFrameSent: function(requestId, time, response)
  15992. {
  15993. var networkRequest = this._inflightRequestsById[requestId];
  15994. if (!networkRequest)
  15995. return;
  15996.  
  15997. networkRequest.addFrame(response, time, true);
  15998. networkRequest.responseReceivedTime = time;
  15999.  
  16000. this._updateNetworkRequest(networkRequest);
  16001. },
  16002.  
  16003.  
  16004. webSocketFrameError: function(requestId, time, errorMessage)
  16005. {
  16006. var networkRequest = this._inflightRequestsById[requestId];
  16007. if (!networkRequest)
  16008. return;
  16009.  
  16010. networkRequest.addFrameError(errorMessage, time);
  16011. networkRequest.responseReceivedTime = time;
  16012.  
  16013. this._updateNetworkRequest(networkRequest);
  16014. },
  16015.  
  16016.  
  16017. webSocketClosed: function(requestId, time)
  16018. {
  16019. var networkRequest = this._inflightRequestsById[requestId];
  16020. if (!networkRequest)
  16021. return;
  16022. this._finishNetworkRequest(networkRequest, time);
  16023. },
  16024.  
  16025.  
  16026. _appendRedirect: function(requestId, time, redirectURL)
  16027. {
  16028. var originalNetworkRequest = this._inflightRequestsById[requestId];
  16029. var previousRedirects = originalNetworkRequest.redirects || [];
  16030. originalNetworkRequest.requestId = "redirected:" + requestId + "." + previousRedirects.length;
  16031. delete originalNetworkRequest.redirects;
  16032. if (previousRedirects.length > 0)
  16033. originalNetworkRequest.redirectSource = previousRedirects[previousRedirects.length - 1];
  16034. this._finishNetworkRequest(originalNetworkRequest, time);
  16035. var newNetworkRequest = this._createNetworkRequest(requestId, originalNetworkRequest.frameId, originalNetworkRequest.loaderId,
  16036. redirectURL, originalNetworkRequest.documentURL, originalNetworkRequest.initiator);
  16037. newNetworkRequest.redirects = previousRedirects.concat(originalNetworkRequest);
  16038. return newNetworkRequest;
  16039. },
  16040.  
  16041.  
  16042. _startNetworkRequest: function(networkRequest)
  16043. {
  16044. this._inflightRequestsById[networkRequest.requestId] = networkRequest;
  16045. this._inflightRequestsByURL[networkRequest.url] = networkRequest;
  16046. this._dispatchEventToListeners(WebInspector.NetworkManager.EventTypes.RequestStarted, networkRequest);
  16047. },
  16048.  
  16049.  
  16050. _updateNetworkRequest: function(networkRequest)
  16051. {
  16052. this._dispatchEventToListeners(WebInspector.NetworkManager.EventTypes.RequestUpdated, networkRequest);
  16053. },
  16054.  
  16055.  
  16056. _finishNetworkRequest: function(networkRequest, finishTime)
  16057. {
  16058. networkRequest.endTime = finishTime;
  16059. networkRequest.finished = true;
  16060. this._dispatchEventToListeners(WebInspector.NetworkManager.EventTypes.RequestFinished, networkRequest);
  16061. delete this._inflightRequestsById[networkRequest.requestId];
  16062. delete this._inflightRequestsByURL[networkRequest.url];
  16063. },
  16064.  
  16065.  
  16066. _dispatchEventToListeners: function(eventType, networkRequest)
  16067. {
  16068. this._manager.dispatchEventToListeners(eventType, networkRequest);
  16069. },
  16070.  
  16071.  
  16072. _createNetworkRequest: function(requestId, frameId, loaderId, url, documentURL, initiator)
  16073. {
  16074. var networkRequest = new WebInspector.NetworkRequest(requestId, url, documentURL, frameId, loaderId);
  16075. networkRequest.initiator = initiator;
  16076. return networkRequest;
  16077. }
  16078. }
  16079.  
  16080.  
  16081. WebInspector.networkManager = null;
  16082.  
  16083.  
  16084.  
  16085.  
  16086.  
  16087.  
  16088. WebInspector.NetworkLog = function()
  16089. {
  16090. this._requests = [];
  16091. this._requestForId = {};
  16092. WebInspector.networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestStarted, this._onRequestStarted, this);
  16093. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, this._onMainFrameNavigated, this);
  16094. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.OnLoad, this._onLoad, this);
  16095. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.DOMContentLoaded, this._onDOMContentLoaded, this);
  16096. }
  16097.  
  16098. WebInspector.NetworkLog.prototype = {
  16099.  
  16100. get requests()
  16101. {
  16102. return this._requests;
  16103. },
  16104.  
  16105.  
  16106. requestForURL: function(url)
  16107. {
  16108. for (var i = 0; i < this._requests.length; ++i) {
  16109. if (this._requests[i].url === url)
  16110. return this._requests[i];
  16111. }
  16112. return null;
  16113. },
  16114.  
  16115.  
  16116. pageLoadForRequest: function(request)
  16117. {
  16118. return request.__page;
  16119. },
  16120.  
  16121.  
  16122. _onMainFrameNavigated: function(event)
  16123. {
  16124. var mainFrame =   event.data;
  16125.  
  16126. this._currentPageLoad = null;
  16127. var oldRequests = this._requests.splice(0, this._requests.length);
  16128. for (var i = 0; i < oldRequests.length; ++i) {
  16129. var request = oldRequests[i];
  16130. if (request.loaderId === mainFrame.loaderId) {
  16131. if (!this._currentPageLoad)
  16132. this._currentPageLoad = new WebInspector.PageLoad(request);
  16133. this._requests.push(request);
  16134. request.__page = this._currentPageLoad;
  16135. }
  16136. }
  16137. },
  16138.  
  16139.  
  16140. _onRequestStarted: function(event)
  16141. {
  16142. var request =   (event.data);
  16143. this._requests.push(request);
  16144. this._requestForId[request.requestId] = request;
  16145. request.__page = this._currentPageLoad;
  16146. },
  16147.  
  16148.  
  16149. _onDOMContentLoaded: function(event)
  16150. {
  16151. if (this._currentPageLoad)
  16152. this._currentPageLoad.contentLoadTime = event.data;
  16153. },
  16154.  
  16155.  
  16156. _onLoad: function(event)
  16157. {
  16158. if (this._currentPageLoad)
  16159. this._currentPageLoad.loadTime = event.data;
  16160. },
  16161.  
  16162.  
  16163. requestForId: function(requestId)
  16164. {
  16165. return this._requestForId[requestId];
  16166. }
  16167. }
  16168.  
  16169.  
  16170. WebInspector.networkLog = null;
  16171.  
  16172.  
  16173. WebInspector.PageLoad = function(mainRequest)
  16174. {
  16175. this.id = ++WebInspector.PageLoad._lastIdentifier;
  16176. this.url = mainRequest.url;
  16177. this.startTime = mainRequest.startTime;
  16178. }
  16179.  
  16180. WebInspector.PageLoad._lastIdentifier = 0;
  16181.  
  16182.  
  16183.  
  16184.  
  16185.  
  16186.  
  16187. WebInspector.ResourceTreeModel = function(networkManager)
  16188. {
  16189. networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestFinished, this._onRequestFinished, this);
  16190. networkManager.addEventListener(WebInspector.NetworkManager.EventTypes.RequestUpdateDropped, this._onRequestUpdateDropped, this);
  16191.  
  16192. WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, this._consoleMessageAdded, this);
  16193. WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.RepeatCountUpdated, this._consoleMessageAdded, this);
  16194. WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.ConsoleCleared, this._consoleCleared, this);
  16195.  
  16196. PageAgent.enable();
  16197.  
  16198. NetworkAgent.enable();
  16199. this._fetchResourceTree();
  16200.  
  16201. InspectorBackend.registerPageDispatcher(new WebInspector.PageDispatcher(this));
  16202.  
  16203. this._pendingConsoleMessages = {};
  16204. }
  16205.  
  16206. WebInspector.ResourceTreeModel.EventTypes = {
  16207. FrameAdded: "FrameAdded",
  16208. FrameNavigated: "FrameNavigated",
  16209. FrameDetached: "FrameDetached",
  16210. MainFrameNavigated: "MainFrameNavigated",
  16211. ResourceAdded: "ResourceAdded",
  16212. WillLoadCachedResources: "WillLoadCachedResources",
  16213. CachedResourcesLoaded: "CachedResourcesLoaded",
  16214. DOMContentLoaded: "DOMContentLoaded",
  16215. OnLoad: "OnLoad",
  16216. InspectedURLChanged: "InspectedURLChanged"
  16217. }
  16218.  
  16219. WebInspector.ResourceTreeModel.prototype = {
  16220. _fetchResourceTree: function()
  16221. {
  16222. this._frames = {};
  16223. delete this._cachedResourcesProcessed;
  16224. PageAgent.getResourceTree(this._processCachedResources.bind(this));
  16225. },
  16226.  
  16227. _processCachedResources: function(error, mainFramePayload)
  16228. {
  16229. if (error) {
  16230. console.error(JSON.stringify(error));
  16231. return;
  16232. }
  16233.  
  16234. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.WillLoadCachedResources);
  16235. WebInspector.inspectedPageURL = mainFramePayload.frame.url;
  16236. this._addFramesRecursively(null, mainFramePayload);
  16237. this._dispatchInspectedURLChanged();
  16238. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.CachedResourcesLoaded);
  16239. this._cachedResourcesProcessed = true;
  16240. },
  16241.  
  16242. cachedResourcesLoaded: function()
  16243. {
  16244. return this._cachedResourcesProcessed;
  16245. },
  16246.  
  16247. _dispatchInspectedURLChanged: function()
  16248. {
  16249. InspectorFrontendHost.inspectedURLChanged(WebInspector.inspectedPageURL);
  16250. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.InspectedURLChanged, WebInspector.inspectedPageURL);
  16251. },
  16252.  
  16253.  
  16254. _addFrame: function(frame)
  16255. {
  16256. this._frames[frame.id] = frame;
  16257. if (frame.isMainFrame())
  16258. this.mainFrame = frame;
  16259. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.FrameAdded, frame);
  16260. },
  16261.  
  16262.  
  16263. _frameNavigated: function(framePayload)
  16264. {
  16265.  
  16266. if (!this._cachedResourcesProcessed)
  16267. return;
  16268. var frame = this._frames[framePayload.id];
  16269. if (frame) {
  16270.  
  16271. frame._navigate(framePayload);
  16272. } else {
  16273.  
  16274. var parentFrame = this._frames[framePayload.parentId];
  16275. frame = new WebInspector.ResourceTreeFrame(this, parentFrame, framePayload);
  16276. if (frame.isMainFrame() && this.mainFrame) {
  16277.  
  16278. this._frameDetached(this.mainFrame.id);
  16279. }
  16280. this._addFrame(frame);
  16281. }
  16282.  
  16283. if (frame.isMainFrame())
  16284. WebInspector.inspectedPageURL = frame.url;
  16285.  
  16286. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.FrameNavigated, frame);
  16287. if (frame.isMainFrame())
  16288. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, frame);
  16289.  
  16290.  
  16291. var resources = frame.resources();
  16292. for (var i = 0; i < resources.length; ++i)
  16293. this.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, resources[i]);
  16294.  
  16295. if (frame.isMainFrame())
  16296. this._dispatchInspectedURLChanged();
  16297. },
  16298.  
  16299.  
  16300. _frameDetached: function(frameId)
  16301. {
  16302.  
  16303. if (!this._cachedResourcesProcessed)
  16304. return;
  16305.  
  16306. var frame = this._frames[frameId];
  16307. if (!frame)
  16308. return;
  16309.  
  16310. if (frame.parentFrame)
  16311. frame.parentFrame._removeChildFrame(frame);
  16312. else
  16313. frame._remove();
  16314. },
  16315.  
  16316.  
  16317. _onRequestFinished: function(event)
  16318. {
  16319. if (!this._cachedResourcesProcessed)
  16320. return;
  16321.  
  16322. var request =   (event.data);
  16323. if (request.failed || request.type === WebInspector.resourceTypes.XHR)
  16324. return;
  16325.  
  16326. var frame = this._frames[request.frameId];
  16327. if (frame) {
  16328. var resource = frame._addRequest(request);
  16329. this._addPendingConsoleMessagesToResource(resource);
  16330. }
  16331. },
  16332.  
  16333.  
  16334. _onRequestUpdateDropped: function(event)
  16335. {
  16336. if (!this._cachedResourcesProcessed)
  16337. return;
  16338.  
  16339. var frameId = event.data.frameId;
  16340. var frame = this._frames[frameId];
  16341. if (!frame)
  16342. return;
  16343.  
  16344. var url = event.data.url;
  16345. if (frame._resourcesMap[url])
  16346. return;
  16347.  
  16348. var resource = new WebInspector.Resource(null, url, frame.url, frameId, event.data.loaderId, WebInspector.resourceTypes[event.data.resourceType], event.data.mimeType);
  16349. frame.addResource(resource);
  16350. },
  16351.  
  16352.  
  16353. frameForId: function(frameId)
  16354. {
  16355. return this._frames[frameId];
  16356. },
  16357.  
  16358.  
  16359. forAllResources: function(callback)
  16360. {
  16361. if (this.mainFrame)
  16362. return this.mainFrame._callForFrameResources(callback);
  16363. return false;
  16364. },
  16365.  
  16366.  
  16367. _consoleMessageAdded: function(event)
  16368. {
  16369. var msg =   (event.data);
  16370. var resource = msg.url ? this.resourceForURL(msg.url) : null;
  16371. if (resource)
  16372. this._addConsoleMessageToResource(msg, resource);
  16373. else
  16374. this._addPendingConsoleMessage(msg);
  16375. },
  16376.  
  16377.  
  16378. _addPendingConsoleMessage: function(msg)
  16379. {
  16380. if (!msg.url)
  16381. return;
  16382. if (!this._pendingConsoleMessages[msg.url])
  16383. this._pendingConsoleMessages[msg.url] = [];
  16384. this._pendingConsoleMessages[msg.url].push(msg);
  16385. },
  16386.  
  16387.  
  16388. _addPendingConsoleMessagesToResource: function(resource)
  16389. {
  16390. var messages = this._pendingConsoleMessages[resource.url];
  16391. if (messages) {
  16392. for (var i = 0; i < messages.length; i++)
  16393. this._addConsoleMessageToResource(messages[i], resource);
  16394. delete this._pendingConsoleMessages[resource.url];
  16395. }
  16396. },
  16397.  
  16398.  
  16399. _addConsoleMessageToResource: function(msg, resource)
  16400. {
  16401. switch (msg.level) {
  16402. case WebInspector.ConsoleMessage.MessageLevel.Warning:
  16403. resource.warnings += msg.repeatDelta;
  16404. break;
  16405. case WebInspector.ConsoleMessage.MessageLevel.Error:
  16406. resource.errors += msg.repeatDelta;
  16407. break;
  16408. }
  16409. resource.addMessage(msg);
  16410. },
  16411.  
  16412. _consoleCleared: function()
  16413. {
  16414. function callback(resource)
  16415. {
  16416. resource.clearErrorsAndWarnings();
  16417. }
  16418.  
  16419. this._pendingConsoleMessages = {};
  16420. this.forAllResources(callback);
  16421. },
  16422.  
  16423.  
  16424. resourceForURL: function(url)
  16425. {
  16426.  
  16427. return this.mainFrame ? this.mainFrame.resourceForURL(url) : null;
  16428. },
  16429.  
  16430.  
  16431. _addFramesRecursively: function(parentFrame, frameTreePayload)
  16432. {
  16433. var framePayload = frameTreePayload.frame;
  16434. var frame = new WebInspector.ResourceTreeFrame(this, parentFrame, framePayload);
  16435. this._addFrame(frame);
  16436.  
  16437. var frameResource = this._createResourceFromFramePayload(framePayload, framePayload.url, WebInspector.resourceTypes.Document, framePayload.mimeType);
  16438. if (frame.isMainFrame())
  16439. WebInspector.inspectedPageURL = frameResource.url;
  16440. frame.addResource(frameResource);
  16441.  
  16442. for (var i = 0; frameTreePayload.childFrames && i < frameTreePayload.childFrames.length; ++i)
  16443. this._addFramesRecursively(frame, frameTreePayload.childFrames[i]);
  16444.  
  16445. for (var i = 0; i < frameTreePayload.resources.length; ++i) {
  16446. var subresource = frameTreePayload.resources[i];
  16447. var resource = this._createResourceFromFramePayload(framePayload, subresource.url, WebInspector.resourceTypes[subresource.type], subresource.mimeType);
  16448. frame.addResource(resource);
  16449. }
  16450. },
  16451.  
  16452.  
  16453. _createResourceFromFramePayload: function(frame, url, type, mimeType)
  16454. {
  16455. return new WebInspector.Resource(null, url, frame.url, frame.id, frame.loaderId, type, mimeType);
  16456. },
  16457.  
  16458. __proto__: WebInspector.Object.prototype
  16459. }
  16460.  
  16461.  
  16462. WebInspector.ResourceTreeFrame = function(model, parentFrame, payload)
  16463. {
  16464. this._model = model;
  16465. this._parentFrame = parentFrame;
  16466.  
  16467. this._id = payload.id;
  16468. this._loaderId = payload.loaderId;
  16469. this._name = payload.name;
  16470. this._url = payload.url;
  16471. this._securityOrigin = payload.securityOrigin || "";
  16472. this._mimeType = payload.mimeType;
  16473.  
  16474.  
  16475. this._childFrames = [];
  16476.  
  16477.  
  16478. this._resourcesMap = {};
  16479.  
  16480. if (this._parentFrame)
  16481. this._parentFrame._childFrames.push(this);
  16482. }
  16483.  
  16484. WebInspector.ResourceTreeFrame.prototype = {
  16485.  
  16486. get id()
  16487. {
  16488. return this._id;
  16489. },
  16490.  
  16491.  
  16492. get name()
  16493. {
  16494. return this._name || "";
  16495. },
  16496.  
  16497.  
  16498. get url()
  16499. {
  16500. return this._url;
  16501. },
  16502.  
  16503.  
  16504. get securityOrigin()
  16505. {
  16506. return this._securityOrigin;
  16507. },
  16508.  
  16509.  
  16510. get loaderId()
  16511. {
  16512. return this._loaderId;
  16513. },
  16514.  
  16515.  
  16516. get parentFrame()
  16517. {
  16518. return this._parentFrame;
  16519. },
  16520.  
  16521.  
  16522. get childFrames()
  16523. {
  16524. return this._childFrames;
  16525. },
  16526.  
  16527.  
  16528. isMainFrame: function()
  16529. {
  16530. return !this._parentFrame;
  16531. },
  16532.  
  16533.  
  16534. _navigate: function(framePayload)
  16535. {
  16536. this._loaderId = framePayload.loaderId;
  16537. this._name = framePayload.name;
  16538. this._url = framePayload.url;
  16539. this._securityOrigin = framePayload.securityOrigin || "";
  16540. this._mimeType = framePayload.mimeType;
  16541.  
  16542. var mainResource = this._resourcesMap[this._url];
  16543. this._resourcesMap = {};
  16544. this._removeChildFrames();
  16545. if (mainResource && mainResource.loaderId === this._loaderId)
  16546. this.addResource(mainResource);
  16547. },
  16548.  
  16549.  
  16550. get mainResource()
  16551. {
  16552. return this._resourcesMap[this._url];
  16553. },
  16554.  
  16555.  
  16556. _removeChildFrame: function(frame)
  16557. {
  16558. this._childFrames.remove(frame);
  16559. frame._remove();
  16560. },
  16561.  
  16562. _removeChildFrames: function()
  16563. {
  16564. var copy = this._childFrames.slice();
  16565. for (var i = 0; i < copy.length; ++i)
  16566. this._removeChildFrame(copy[i]); 
  16567. },
  16568.  
  16569. _remove: function()
  16570. {
  16571. this._removeChildFrames();
  16572. delete this._model._frames[this.id];
  16573. this._model.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.FrameDetached, this);
  16574. },
  16575.  
  16576.  
  16577. addResource: function(resource)
  16578. {
  16579. if (this._resourcesMap[resource.url] === resource) {
  16580.  
  16581. return;
  16582. }
  16583. this._resourcesMap[resource.url] = resource;
  16584. this._model.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, resource);
  16585. },
  16586.  
  16587.  
  16588. _addRequest: function(request)
  16589. {
  16590. var resource = this._resourcesMap[request.url];
  16591. if (resource && resource.request === request) {
  16592.  
  16593. return resource;
  16594. }
  16595. resource = new WebInspector.Resource(request, request.url, request.documentURL, request.frameId, request.loaderId, request.type, request.mimeType);
  16596. this._resourcesMap[resource.url] = resource;
  16597. this._model.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, resource);
  16598. return resource;
  16599. },
  16600.  
  16601.  
  16602. resources: function()
  16603. {
  16604. var result = [];
  16605. for (var url in this._resourcesMap)
  16606. result.push(this._resourcesMap[url]);
  16607. return result;
  16608. },
  16609.  
  16610.  
  16611. resourceForURL: function(url)
  16612. {
  16613. var result;
  16614. function filter(resource)
  16615. {
  16616. if (resource.url === url) {
  16617. result = resource;
  16618. return true;
  16619. }
  16620. }
  16621. this._callForFrameResources(filter);
  16622. return result;
  16623. },
  16624.  
  16625.  
  16626. _callForFrameResources: function(callback)
  16627. {
  16628. for (var url in this._resourcesMap) {
  16629. if (callback(this._resourcesMap[url]))
  16630. return true;
  16631. }
  16632.  
  16633. for (var i = 0; i < this._childFrames.length; ++i) {
  16634. if (this._childFrames[i]._callForFrameResources(callback))
  16635. return true;
  16636. }
  16637. return false;
  16638. }
  16639. }
  16640.  
  16641.  
  16642. WebInspector.PageDispatcher = function(resourceTreeModel)
  16643. {
  16644. this._resourceTreeModel = resourceTreeModel;
  16645. }
  16646.  
  16647. WebInspector.PageDispatcher.prototype = {
  16648. domContentEventFired: function(time)
  16649. {
  16650. this._resourceTreeModel.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.DOMContentLoaded, time);
  16651. },
  16652.  
  16653. loadEventFired: function(time)
  16654. {
  16655. this._resourceTreeModel.dispatchEventToListeners(WebInspector.ResourceTreeModel.EventTypes.OnLoad, time);
  16656. },
  16657.  
  16658. frameNavigated: function(frame)
  16659. {
  16660. this._resourceTreeModel._frameNavigated(frame);
  16661. },
  16662.  
  16663. frameDetached: function(frameId)
  16664. {
  16665. this._resourceTreeModel._frameDetached(frameId);
  16666. }
  16667. }
  16668.  
  16669.  
  16670. WebInspector.resourceTreeModel = null;
  16671.  
  16672.  
  16673.  
  16674.  
  16675.  
  16676.  
  16677. WebInspector.ParsedURL = function(url)
  16678. {
  16679. this.isValid = false;
  16680. this.url = url;
  16681. this.scheme = "";
  16682. this.host = "";
  16683. this.port = "";
  16684. this.path = "";
  16685. this.queryParams = "";
  16686. this.fragment = "";
  16687. this.folderPathComponents = "";
  16688. this.lastPathComponent = "";
  16689.  
  16690.  
  16691.  
  16692.  
  16693.  
  16694.  
  16695.  
  16696. var match = url.match(/^([A-Za-z][A-Za-z0-9+.-]*):\/\/([^\/:]*)(?::([\d]+))?(?:(\/[^#]*)(?:#(.*))?)?$/i);
  16697. if (match) {
  16698. this.isValid = true;
  16699. this.scheme = match[1].toLowerCase();
  16700. this.host = match[2];
  16701. this.port = match[3];
  16702. this.path = match[4] || "/";
  16703. this.fragment = match[5];
  16704. } else {
  16705. if (this.url.startsWith("data:")) {
  16706. this.scheme = "data";
  16707. return;
  16708. }
  16709. if (this.url === "about:blank") {
  16710. this.scheme = "about";
  16711. return;
  16712. }
  16713. this.path = this.url;
  16714. }
  16715.  
  16716.  
  16717. var path = this.path;
  16718. var indexOfQuery = path.indexOf("?");
  16719. if (indexOfQuery !== -1) {
  16720. this.queryParams = path.substring(indexOfQuery + 1)
  16721. path = path.substring(0, indexOfQuery);
  16722. }
  16723.  
  16724.  
  16725. var lastSlashIndex = path.lastIndexOf("/");
  16726. if (lastSlashIndex !== -1) {
  16727. this.folderPathComponents = path.substring(0, lastSlashIndex);
  16728. this.lastPathComponent = path.substring(lastSlashIndex + 1);
  16729. } else
  16730. this.lastPathComponent = path;
  16731. }
  16732.  
  16733.  
  16734. WebInspector.ParsedURL.completeURL = function(baseURL, href)
  16735. {
  16736. if (href) {
  16737.  
  16738. var trimmedHref = href.trim();
  16739. if (trimmedHref.startsWith("data:") || trimmedHref.startsWith("blob:") || trimmedHref.startsWith("javascript:"))
  16740. return href;
  16741.  
  16742.  
  16743. var parsedHref = trimmedHref.asParsedURL();
  16744. if (parsedHref && parsedHref.scheme)
  16745. return trimmedHref;
  16746. } else
  16747. return baseURL;
  16748.  
  16749. var parsedURL = baseURL.asParsedURL();
  16750. if (parsedURL) {
  16751. var path = href;
  16752. if (path.charAt(0) !== "/") {
  16753. var basePath = parsedURL.path;
  16754.  
  16755.  
  16756. var questionMarkIndex = basePath.indexOf("?");
  16757. if (questionMarkIndex > 0)
  16758. basePath = basePath.substring(0, questionMarkIndex);
  16759.  
  16760.  
  16761. var prefix;
  16762. if (path.charAt(0) === "?") {
  16763. var basePathCutIndex = basePath.indexOf("?");
  16764. if (basePathCutIndex !== -1)
  16765. prefix = basePath.substring(0, basePathCutIndex);
  16766. else
  16767. prefix = basePath;
  16768. } else
  16769. prefix = basePath.substring(0, basePath.lastIndexOf("/")) + "/";
  16770.  
  16771. path = prefix + path;
  16772. } else if (path.length > 1 && path.charAt(1) === "/") {
  16773.  
  16774. return parsedURL.scheme + ":" + path;
  16775. }
  16776. return parsedURL.scheme + "://" + parsedURL.host + (parsedURL.port ? (":" + parsedURL.port) : "") + path;
  16777. }
  16778. return null;
  16779. }
  16780.  
  16781. WebInspector.ParsedURL.prototype = {
  16782. get displayName()
  16783. {
  16784. if (this._displayName)
  16785. return this._displayName;
  16786.  
  16787. if (this.isDataURL())
  16788. return this.dataURLDisplayName();
  16789. if (this.isAboutBlank())
  16790. return this.url;
  16791.  
  16792. this._displayName = this.lastPathComponent;
  16793. if (!this._displayName)
  16794. this._displayName = this.host;
  16795. if (!this._displayName && this.url)
  16796. this._displayName = this.url.trimURL(WebInspector.inspectedPageDomain ? WebInspector.inspectedPageDomain : "");
  16797. if (this._displayName === "/")
  16798. this._displayName = this.url;
  16799. return this._displayName;
  16800. },
  16801.  
  16802. dataURLDisplayName: function()
  16803. {
  16804. if (this._dataURLDisplayName)
  16805. return this._dataURLDisplayName;
  16806. if (!this.isDataURL())
  16807. return "";
  16808. this._dataURLDisplayName = this.url.trimEnd(20);
  16809. return this._dataURLDisplayName;
  16810. },
  16811.  
  16812. isAboutBlank: function()
  16813. {
  16814. return this.url === "about:blank";
  16815. },
  16816.  
  16817. isDataURL: function()
  16818. {
  16819. return this.scheme === "data";
  16820. }
  16821. }
  16822.  
  16823.  
  16824. String.prototype.asParsedURL = function()
  16825. {
  16826. var parsedURL = new WebInspector.ParsedURL(this.toString());
  16827. if (parsedURL.isValid)
  16828. return parsedURL;
  16829. return null;
  16830. }
  16831.  
  16832.  
  16833.  
  16834.  
  16835.  
  16836.  
  16837. WebInspector.resourceForURL = function(url)
  16838. {
  16839. return WebInspector.resourceTreeModel.resourceForURL(url);
  16840. }
  16841.  
  16842.  
  16843. WebInspector.forAllResources = function(callback)
  16844. {
  16845. WebInspector.resourceTreeModel.forAllResources(callback);
  16846. }
  16847.  
  16848.  
  16849. WebInspector.displayNameForURL = function(url)
  16850. {
  16851. if (!url)
  16852. return "";
  16853.  
  16854. var resource = WebInspector.resourceForURL(url);
  16855. if (resource)
  16856. return resource.displayName;
  16857.  
  16858. var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url);
  16859. if (uiSourceCode)
  16860. return uiSourceCode.parsedURL.displayName;
  16861.  
  16862. if (!WebInspector.inspectedPageURL)
  16863. return url.trimURL("");
  16864.  
  16865. var parsedURL = WebInspector.inspectedPageURL.asParsedURL();
  16866. var lastPathComponent = parsedURL ? parsedURL.lastPathComponent : parsedURL;
  16867. var index = WebInspector.inspectedPageURL.indexOf(lastPathComponent);
  16868. if (index !== -1 && index + lastPathComponent.length === WebInspector.inspectedPageURL.length) {
  16869. var baseURL = WebInspector.inspectedPageURL.substring(0, index);
  16870. if (url.startsWith(baseURL))
  16871. return url.substring(index);
  16872. }
  16873.  
  16874. return parsedURL ? url.trimURL(parsedURL.host) : url;
  16875. }
  16876.  
  16877.  
  16878. WebInspector.linkifyStringAsFragmentWithCustomLinkifier = function(string, linkifier)
  16879. {
  16880. var container = document.createDocumentFragment();
  16881. var linkStringRegEx = /(?:[a-zA-Z][a-zA-Z0-9+.-]{2,}:\/\/|data:|www\.)[\w$\-_+*'=\|\/\\(){}[\]^%@&#~,:;.!?]{2,}[\w$\-_+*=\|\/\\({^%@&#~]/;
  16882.     var lineColumnRegEx = /:(\d+)(:(\d+))?$/;
  16883.  
  16884.     while (string) {
  16885.         var linkString = linkStringRegEx.exec(string);
  16886.         if (!linkString)
  16887.             break;
  16888.  
  16889.         linkString = linkString[0];
  16890.         var linkIndex = string.indexOf(linkString);
  16891.         var nonLink = string.substring(0, linkIndex);
  16892.         container.appendChild(document.createTextNode(nonLink));
  16893.  
  16894.         var title = linkString;
  16895.         var realURL = (linkString.startsWith("www.") ? "http://" + linkString : linkString);
  16896.         var lineColumnMatch = lineColumnRegEx.exec(realURL);
  16897.         var lineNumber;
  16898.         if (lineColumnMatch) {
  16899.             realURL = realURL.substring(0, realURL.length - lineColumnMatch[0].length);
  16900.             lineNumber = parseInt(lineColumnMatch[1], 10);
  16901.             lineNumber = isNaN(lineNumber) ? undefined : lineNumber;
  16902.         }
  16903.  
  16904.         var linkNode = linkifier(title, realURL, lineNumber);
  16905.         container.appendChild(linkNode);
  16906.         string = string.substring(linkIndex + linkString.length, string.length);
  16907.     }
  16908.  
  16909.     if (string)
  16910.         container.appendChild(document.createTextNode(string));
  16911.  
  16912.     return container;
  16913. }
  16914.  
  16915. WebInspector._linkifierPlugins = [];
  16916.  
  16917. /**
  16918.  * @param {function(string):string} plugin
  16919.  */
  16920. WebInspector.registerLinkifierPlugin = function(plugin)
  16921. {
  16922.     WebInspector._linkifierPlugins.push(plugin);
  16923. }
  16924.  
  16925. /**
  16926.  * @param {string} string
  16927.  * @return {DocumentFragment}
  16928.  */
  16929. WebInspector.linkifyStringAsFragment = function(string)
  16930. {
  16931.     /**
  16932.      * @param {string} title
  16933.      * @param {string} url
  16934.      * @param {number=} lineNumber
  16935.      * @return {Node}
  16936.      */
  16937.     function linkifier(title, url, lineNumber)
  16938.     {
  16939.         for (var i = 0; i < WebInspector._linkifierPlugins.length; ++i)
  16940.             title = WebInspector._linkifierPlugins[i](title);
  16941.  
  16942.         var isExternal = !WebInspector.resourceForURL(url);
  16943.         var urlNode = WebInspector.linkifyURLAsNode(url, title, undefined, isExternal);
  16944.         if (typeof(lineNumber) !== "undefined") {
  16945.             urlNode.lineNumber = lineNumber;
  16946.             urlNode.preferredPanel = "scripts";
  16947.         }
  16948.         
  16949.         return urlNode; 
  16950.     }
  16951.     
  16952.     return WebInspector.linkifyStringAsFragmentWithCustomLinkifier(string, linkifier);
  16953. }
  16954.  
  16955. /**
  16956.  * @param {string} url
  16957.  * @param {string=} linkText
  16958.  * @param {string=} classes
  16959.  * @param {boolean=} isExternal
  16960.  * @param {string=} tooltipText
  16961.  * @return {!Element}
  16962.  */
  16963. WebInspector.linkifyURLAsNode = function(url, linkText, classes, isExternal, tooltipText)
  16964. {
  16965.     if (!linkText)
  16966.         linkText = url;
  16967.     classes = (classes ? classes + " " : "");
  16968.     classes += isExternal ? "webkit-html-external-link" : "webkit-html-resource-link";
  16969.  
  16970.     var a = document.createElement("a");
  16971.     a.href = sanitizeHref(url);
  16972.     a.className = classes;
  16973.     if (typeof tooltipText === "undefined")
  16974.         a.title = url;
  16975.     else if (typeof tooltipText !== "string" || tooltipText.length)
  16976.         a.title = tooltipText;
  16977.     a.textContent = linkText.trimMiddle(WebInspector.Linkifier.MaxLengthForDisplayedURLs);
  16978.     if (isExternal)
  16979.         a.setAttribute("target", "_blank");
  16980.  
  16981.     return a;
  16982. }
  16983.  
  16984. /**
  16985.  * @param {string} url
  16986.  * @param {number=} lineNumber
  16987.  * @return {string}
  16988.  */
  16989. WebInspector.formatLinkText = function(url, lineNumber)
  16990. {
  16991.     var text = url ? WebInspector.displayNameForURL(url) : WebInspector.UIString("(program)");
  16992.     if (typeof lineNumber === "number")
  16993.         text += ":" + (lineNumber + 1);
  16994.     return text;
  16995. }
  16996.  
  16997. /**
  16998.  * @param {string} url
  16999.  * @param {number=} lineNumber
  17000.  * @param {string=} classes
  17001.  * @param {string=} tooltipText
  17002.  * @return {Element}
  17003.  */
  17004. WebInspector.linkifyResourceAsNode = function(url, lineNumber, classes, tooltipText)
  17005. {
  17006.     var linkText = WebInspector.formatLinkText(url, lineNumber);
  17007.     var anchor = WebInspector.linkifyURLAsNode(url, linkText, classes, false, tooltipText);
  17008.     anchor.preferredPanel = "resources";
  17009.     anchor.lineNumber = lineNumber;
  17010.     return anchor;
  17011. }
  17012.  
  17013. /**
  17014.  * @param {WebInspector.NetworkRequest} request
  17015.  * @param {string=} classes
  17016.  * @return {Element}
  17017.  */
  17018. WebInspector.linkifyRequestAsNode = function(request, classes)
  17019. {
  17020.     var anchor = WebInspector.linkifyURLAsNode(request.url);
  17021.     anchor.preferredPanel = "network";
  17022.     anchor.requestId  = request.requestId;
  17023.     return anchor;
  17024. }
  17025.  
  17026. /**
  17027.  * @param {string} content
  17028.  * @param {string} mimeType
  17029.  * @param {boolean} contentEncoded
  17030.  * @return {?string}
  17031.  */
  17032. WebInspector.contentAsDataURL = function(content, mimeType, contentEncoded)
  17033. {
  17034.     const maxDataUrlSize = 1024 * 1024;
  17035.     if (content == null || content.length > maxDataUrlSize)
  17036.         return null;
  17037.  
  17038.     return "data:" + mimeType + (contentEncoded ? ";base64," : ",") + content;
  17039. }
  17040.  
  17041. /* ResourceType.js */
  17042.  
  17043. /*
  17044.  * Copyright (C) 2012 Google Inc.  All rights reserved.
  17045.  * Copyright (C) 2007, 2008 Apple Inc.  All rights reserved.
  17046.  *
  17047.  * Redistribution and use in source and binary forms, with or without
  17048.  * modification, are permitted provided that the following conditions
  17049.  * are met:
  17050.  *
  17051.  * 1.  Redistributions of source code must retain the above copyright
  17052.  *     notice, this list of conditions and the following disclaimer.
  17053.  * 2.  Redistributions in binary form must reproduce the above copyright
  17054.  *     notice, this list of conditions and the following disclaimer in the
  17055.  *     documentation and/or other materials provided with the distribution.
  17056.  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  17057.  *     its contributors may be used to endorse or promote products derived
  17058.  *     from this software without specific prior written permission.
  17059.  *
  17060.  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  17061.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17062.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17063.  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  17064.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  17065.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  17066.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  17067.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  17068.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  17069.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17070.  */
  17071.  
  17072. /**
  17073.  * @constructor
  17074.  * @param {string} name
  17075.  * @param {string} title
  17076.  * @param {string} categoryTitle
  17077.  * @param {string} color
  17078.  * @param {boolean} isTextType
  17079.  */
  17080. WebInspector.ResourceType = function(name, title, categoryTitle, color, isTextType)
  17081. {
  17082.     this._name = name;
  17083.     this._title = title;
  17084.     this._categoryTitle = categoryTitle;
  17085.     this._color = color;
  17086.     this._isTextType = isTextType;
  17087. }
  17088.  
  17089. WebInspector.ResourceType.prototype = {
  17090.     /**
  17091.      * @return {string}
  17092.      */
  17093.     name: function()
  17094.     {
  17095.         return this._name;
  17096.     },
  17097.  
  17098.     /**
  17099.      * @return {string}
  17100.      */
  17101.     title: function()
  17102.     {
  17103.         return this._title;
  17104.     },
  17105.  
  17106.     /**
  17107.      * @return {string}
  17108.      */
  17109.     categoryTitle: function()
  17110.     {
  17111.         return this._categoryTitle;
  17112.     },
  17113.  
  17114.     /**
  17115.      * @return {string}
  17116.      */
  17117.     color: function()
  17118.     {
  17119.         return this._color;
  17120.     },
  17121.  
  17122.     /**
  17123.      * @return {boolean}
  17124.      */
  17125.     isTextType: function()
  17126.     {
  17127.         return this._isTextType;
  17128.     },
  17129.  
  17130.     /**
  17131.      * @return {string}
  17132.      */
  17133.     toString: function()
  17134.     {
  17135.         return this._name;
  17136.     },
  17137.  
  17138.     /**
  17139.      * @return {string}
  17140.      */
  17141.     canonicalMimeType: function()
  17142.     {
  17143.         if (this === WebInspector.resourceTypes.Document)
  17144.             return "text/html";
  17145.         if (this === WebInspector.resourceTypes.Script)
  17146.             return "text/javascript";
  17147.         if (this === WebInspector.resourceTypes.Stylesheet)
  17148.             return "text/css";
  17149.         return "";
  17150.     }
  17151. }
  17152.  
  17153. /**
  17154.  * Keep these in sync with WebCore::InspectorPageAgent::resourceTypeJson
  17155.  * @enum {!WebInspector.ResourceType}
  17156.  */
  17157. WebInspector.resourceTypes = {
  17158.     Document: new WebInspector.ResourceType("document", "Document", "Documents", "rgb(47,102,236)", true),
  17159.     Stylesheet: new WebInspector.ResourceType("stylesheet", "Stylesheet", "Stylesheets", "rgb(157,231,119)", true),
  17160.     Image: new WebInspector.ResourceType("image", "Image", "Images", "rgb(164,60,255)", false),
  17161.     Script: new WebInspector.ResourceType("script", "Script", "Scripts", "rgb(255,121,0)", true),
  17162.     XHR: new WebInspector.ResourceType("xhr", "XHR", "XHR", "rgb(231,231,10)", true),
  17163.     Font: new WebInspector.ResourceType("font", "Font", "Fonts", "rgb(255,82,62)", false),
  17164.     WebSocket: new WebInspector.ResourceType("websocket", "WebSocket", "WebSockets", "rgb(186,186,186)", false), // FIXME: Decide the color.
  17165.     Other: new WebInspector.ResourceType("other", "Other", "Other", "rgb(186,186,186)", false)
  17166. }
  17167.  
  17168. /* TimelineManager.js */
  17169.  
  17170. /*
  17171.  * Copyright (C) 2011 Google Inc. All rights reserved.
  17172.  *
  17173.  * Redistribution and use in source and binary forms, with or without
  17174.  * modification, are permitted provided that the following conditions are
  17175.  * met:
  17176.  *
  17177.  *     * Redistributions of source code must retain the above copyright
  17178.  * notice, this list of conditions and the following disclaimer.
  17179.  *     * Redistributions in binary form must reproduce the above
  17180.  * copyright notice, this list of conditions and the following disclaimer
  17181.  * in the documentation and/or other materials provided with the
  17182.  * distribution.
  17183.  *     * Neither the name of Google Inc. nor the names of its
  17184.  * contributors may be used to endorse or promote products derived from
  17185.  * this software without specific prior written permission.
  17186.  *
  17187.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17188.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17189.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17190.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  17191.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17192.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  17193.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  17194.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  17195.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  17196.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  17197.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17198.  */
  17199.  
  17200. /**
  17201.  * @constructor
  17202.  * @extends {WebInspector.Object}
  17203.  */
  17204. WebInspector.TimelineManager = function()
  17205. {
  17206.     WebInspector.Object.call(this);
  17207.     this._dispatcher = new WebInspector.TimelineDispatcher(this);
  17208.     this._enablementCount = 0;
  17209. }
  17210.  
  17211. WebInspector.TimelineManager.EventTypes = {
  17212.     TimelineStarted: "TimelineStarted",
  17213.     TimelineStopped: "TimelineStopped",
  17214.     TimelineEventRecorded: "TimelineEventRecorded"
  17215. }
  17216.  
  17217. WebInspector.TimelineManager.prototype = {
  17218.     /**
  17219.      * @param {number=} maxCallStackDepth
  17220.      */
  17221.     start: function(maxCallStackDepth)
  17222.     {
  17223.         this._enablementCount++;
  17224.         if (this._enablementCount === 1)
  17225.             TimelineAgent.start(maxCallStackDepth, this._started.bind(this));
  17226.     },
  17227.  
  17228.     stop: function()
  17229.     {
  17230.         if (!this._enablementCount) {
  17231.             console.error("WebInspector.TimelineManager start/stop calls are unbalanced");
  17232.             return;
  17233.         }
  17234.         this._enablementCount--;
  17235.         if (!this._enablementCount)
  17236.             TimelineAgent.stop(this._stopped.bind(this));
  17237.     },
  17238.  
  17239.     _started: function()
  17240.     {
  17241.         this.dispatchEventToListeners(WebInspector.TimelineManager.EventTypes.TimelineStarted);
  17242.     },
  17243.  
  17244.     _stopped: function()
  17245.     {
  17246.         this.dispatchEventToListeners(WebInspector.TimelineManager.EventTypes.TimelineStopped);
  17247.     },
  17248.  
  17249.     __proto__: WebInspector.Object.prototype
  17250. }
  17251.  
  17252. /**
  17253.  * @constructor
  17254.  * @implements {TimelineAgent.Dispatcher}
  17255.  */
  17256. WebInspector.TimelineDispatcher = function(manager)
  17257. {
  17258.     this._manager = manager;
  17259.     InspectorBackend.registerTimelineDispatcher(this);
  17260. }
  17261.  
  17262. WebInspector.TimelineDispatcher.prototype = {
  17263.     eventRecorded: function(record)
  17264.     {
  17265.         this._manager.dispatchEventToListeners(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, record);
  17266.     }
  17267. }
  17268.  
  17269. /**
  17270.  * @type {WebInspector.TimelineManager}
  17271.  */
  17272. WebInspector.timelineManager;
  17273.  
  17274. /* UserAgentSupport.js */
  17275.  
  17276. /*
  17277.  * Copyright (C) 2012 Google Inc. All rights reserved.
  17278.  *
  17279.  * Redistribution and use in source and binary forms, with or without
  17280.  * modification, are permitted provided that the following conditions are
  17281.  * met:
  17282.  *
  17283.  *     * Redistributions of source code must retain the above copyright
  17284.  * notice, this list of conditions and the following disclaimer.
  17285.  *     * Redistributions in binary form must reproduce the above
  17286.  * copyright notice, this list of conditions and the following disclaimer
  17287.  * in the documentation and/or other materials provided with the
  17288.  * distribution.
  17289.  *     * Neither the name of Google Inc. nor the names of its
  17290.  * contributors may be used to endorse or promote products derived from
  17291.  * this software without specific prior written permission.
  17292.  *
  17293.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  17294.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  17295.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17296.  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  17297.  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  17298.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  17299.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  17300.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  17301.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  17302.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  17303.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17304.  */
  17305.  
  17306. /**
  17307.  * @constructor
  17308.  */
  17309. WebInspector.UserAgentSupport = function()
  17310. {
  17311.     this._userAgentOverrideEnabled = false;
  17312.     this._deviceMetricsOverrideEnabled = false;
  17313.     this._geolocationPositionOverrideEnabled = false;
  17314.     this._deviceOrientationOverrideEnabled = false;
  17315.  
  17316.     WebInspector.settings.userAgent.addChangeListener(this._userAgentChanged, this);
  17317.     WebInspector.settings.deviceMetrics.addChangeListener(this._deviceMetricsChanged, this);
  17318.     WebInspector.settings.deviceFitWindow.addChangeListener(this._deviceMetricsChanged, this);
  17319.     WebInspector.settings.geolocationOverride.addChangeListener(this._geolocationPositionChanged, this);
  17320.     WebInspector.settings.deviceOrientationOverride.addChangeListener(this._deviceOrientationChanged, this);
  17321. }
  17322.  
  17323. /**
  17324.  * @constructor
  17325.  * @param {number} width
  17326.  * @param {number} height
  17327.  * @param {number} fontScaleFactor
  17328.  */
  17329. WebInspector.UserAgentSupport.DeviceMetrics = function(width, height, fontScaleFactor)
  17330. {
  17331.     this.width = width;
  17332.     this.height = height;
  17333.     this.fontScaleFactor = fontScaleFactor;
  17334. }
  17335.  
  17336. /**
  17337.  * @return {WebInspector.UserAgentSupport.DeviceMetrics}
  17338.  */
  17339. WebInspector.UserAgentSupport.DeviceMetrics.parseSetting = function(value)
  17340. {
  17341.     if (value) {
  17342.         var splitMetrics = value.split("x");
  17343.         if (splitMetrics.length === 3)
  17344.             return new WebInspector.UserAgentSupport.DeviceMetrics(parseInt(splitMetrics[0], 10), parseInt(splitMetrics[1], 10), parseFloat(splitMetrics[2]));
  17345.     }
  17346.     return new WebInspector.UserAgentSupport.DeviceMetrics(0, 0, 1);
  17347. }
  17348.  
  17349. /**
  17350.  * @return {?WebInspector.UserAgentSupport.DeviceMetrics}
  17351.  */
  17352. WebInspector.UserAgentSupport.DeviceMetrics.parseUserInput = function(widthString, heightString, fontScaleFactorString)
  17353. {
  17354.     function isUserInputValid(value, isInteger)
  17355.     {
  17356.         if (!value)
  17357.             return true;
  17358.         return isInteger ? /^[0]*[1-9][\d]*$/.test(value) : /^[0]*([1-9][\d]*(\.\d+)?|\.\d+)$/.test(value);
  17359.     }
  17360.  
  17361.     if (!widthString ^ !heightString)
  17362.         return null;
  17363.  
  17364.     var isWidthValid = isUserInputValid(widthString, true);
  17365.     var isHeightValid = isUserInputValid(heightString, true);
  17366.     var isFontScaleFactorValid = isUserInputValid(fontScaleFactorString, false);
  17367.  
  17368.     if (!isWidthValid && !isHeightValid && !isFontScaleFactorValid)
  17369.         return null;
  17370.  
  17371.     var width = isWidthValid ? parseInt(widthString || "0", 10) : -1;
  17372.     var height = isHeightValid ? parseInt(heightString || "0", 10) : -1;
  17373.     var fontScaleFactor = isFontScaleFactorValid ? parseFloat(fontScaleFactorString) : -1;
  17374.  
  17375.     return new WebInspector.UserAgentSupport.DeviceMetrics(width, height, fontScaleFactor);
  17376. }
  17377.  
  17378. WebInspector.UserAgentSupport.DeviceMetrics.prototype = {
  17379.     /**
  17380.      * @return {boolean}
  17381.      */
  17382.     isValid: function()
  17383.     {
  17384.         return this.isWidthValid() && this.isHeightValid() && this.isFontScaleFactorValid();
  17385.     },
  17386.  
  17387.     /**
  17388.      * @return {boolean}
  17389.      */
  17390.     isWidthValid: function()
  17391.     {
  17392.         return this.width >= 0;
  17393.     },
  17394.  
  17395.     /**
  17396.      * @return {boolean}
  17397.      */
  17398.     isHeightValid: function()
  17399.     {
  17400.         return this.height >= 0;
  17401.     },
  17402.  
  17403.     /**
  17404.      * @return {boolean}
  17405.      */
  17406.     isFontScaleFactorValid: function()
  17407.     {
  17408.         return this.fontScaleFactor > 0;
  17409.     },
  17410.  
  17411.     /**
  17412.      * @return {string}
  17413.      */
  17414.     toSetting: function()
  17415.     {
  17416.         if (!this.isValid())
  17417.             return "";
  17418.  
  17419.         return this.width && this.height ? this.width + "x" + this.height + "x" + this.fontScaleFactor : "";
  17420.     },
  17421.  
  17422.     /**
  17423.      * @return {string}
  17424.      */
  17425.     widthToInput: function()
  17426.     {
  17427.         return this.isWidthValid() && this.width ? String(this.width) : "";
  17428.     },
  17429.  
  17430.     /**
  17431.      * @return {string}
  17432.      */
  17433.     heightToInput: function()
  17434.     {
  17435.         return this.isHeightValid() && this.height ? String(this.height) : "";
  17436.     },
  17437.  
  17438.     /**
  17439.      * @return {string}
  17440.      */
  17441.     fontScaleFactorToInput: function()
  17442.     {
  17443.         return this.isFontScaleFactorValid() && this.fontScaleFactor ? String(this.fontScaleFactor) : "";
  17444.     }
  17445. }
  17446.  
  17447. /**
  17448.  * @constructor
  17449.  * @param {number} latitude
  17450.  * @param {number} longitude
  17451.  */
  17452. WebInspector.UserAgentSupport.GeolocationPosition = function(latitude, longitude, error)
  17453. {
  17454.     this.latitude = latitude;
  17455.     this.longitude = longitude;
  17456.     this.error = error;
  17457. }
  17458.  
  17459. WebInspector.UserAgentSupport.GeolocationPosition.prototype = {
  17460.     /**
  17461.      * @return {string}
  17462.      */
  17463.     toSetting: function()
  17464.     {
  17465.         return (typeof this.latitude === "number" && typeof this.longitude === "number" && typeof this.error === "string") ? this.latitude + "@" + this.longitude + ":" + this.error : "";
  17466.     }
  17467. }
  17468.  
  17469. /**
  17470.  * @return {WebInspector.UserAgentSupport.GeolocationPosition}
  17471.  */
  17472. WebInspector.UserAgentSupport.GeolocationPosition.parseSetting = function(value)
  17473. {
  17474.     if (value) {
  17475.         var splitError = value.split(":");
  17476.         if (splitError.length === 2) {
  17477.             var splitPosition = splitError[0].split("@")
  17478.             if (splitPosition.length === 2)
  17479.                 return new WebInspector.UserAgentSupport.GeolocationPosition(parseFloat(splitPosition[0]), parseFloat(splitPosition[1]), splitError[1]);
  17480.         }
  17481.     }
  17482.     return new WebInspector.UserAgentSupport.GeolocationPosition(0, 0, "");
  17483. }
  17484.  
  17485. /**
  17486.  * @return {?WebInspector.UserAgentSupport.GeolocationPosition}
  17487.  */
  17488. WebInspector.UserAgentSupport.GeolocationPosition.parseUserInput = function(latitudeString, longitudeString, errorStatus)
  17489. {
  17490.     function isUserInputValid(value)
  17491.     {
  17492.         if (!value)
  17493.             return true;
  17494.         return /^[-]?[0-9]*[.]?[0-9]*$/.test(value);
  17495.     }
  17496.  
  17497.     if (!latitudeString ^ !latitudeString)
  17498.         return null;
  17499.  
  17500.     var isLatitudeValid = isUserInputValid(latitudeString);
  17501.     var isLongitudeValid = isUserInputValid(longitudeString);
  17502.  
  17503.     if (!isLatitudeValid && !isLongitudeValid)
  17504.         return null;
  17505.  
  17506.     var latitude = isLatitudeValid ? parseFloat(latitudeString) : -1;
  17507.     var longitude = isLongitudeValid ? parseFloat(longitudeString) : -1;
  17508.  
  17509.     return new WebInspector.UserAgentSupport.GeolocationPosition(latitude, longitude, errorStatus ? "PositionUnavailable" : "");
  17510. }
  17511.  
  17512. WebInspector.UserAgentSupport.GeolocationPosition.clearGeolocationOverride = function()
  17513. {
  17514.     PageAgent.clearGeolocationOverride();
  17515. }
  17516.  
  17517. /**
  17518.  * @constructor
  17519.  * @param {number} alpha
  17520.  * @param {number} beta
  17521.  * @param {number} gamma
  17522.  */
  17523. WebInspector.UserAgentSupport.DeviceOrientation = function(alpha, beta, gamma)
  17524. {
  17525.     this.alpha = alpha;
  17526.     this.beta = beta;
  17527.     this.gamma = gamma;
  17528. }
  17529.  
  17530. WebInspector.UserAgentSupport.DeviceOrientation.prototype = {
  17531.     /**
  17532.      * @return {string}
  17533.      */
  17534.     toSetting: function()
  17535.     {
  17536.         return JSON.stringify(this);
  17537.     }
  17538. }
  17539.  
  17540. /**
  17541.  * @return {WebInspector.UserAgentSupport.DeviceOrientation}
  17542.  */
  17543. WebInspector.UserAgentSupport.DeviceOrientation.parseSetting = function(value)
  17544. {
  17545.     if (value) {
  17546.         var jsonObject = JSON.parse(value);
  17547.         return new WebInspector.UserAgentSupport.DeviceOrientation(jsonObject.alpha, jsonObject.beta, jsonObject.gamma);
  17548.     }
  17549.     return new WebInspector.UserAgentSupport.DeviceOrientation(0, 0, 0);
  17550. }
  17551.  
  17552. /**
  17553.  * @return {?WebInspector.UserAgentSupport.DeviceOrientation}
  17554.  */
  17555. WebInspector.UserAgentSupport.DeviceOrientation.parseUserInput = function(alphaString, betaString, gammaString)
  17556. {
  17557.     function isUserInputValid(value)
  17558.     {
  17559.         if (!value)
  17560.             return true;
  17561.         return /^[-]?[0-9]*[.]?[0-9]*$/.test(value);
  17562.     }
  17563.  
  17564.     if (!alphaString ^ !betaString ^ !gammaString)
  17565.         return null;
  17566.  
  17567.     var isAlphaValid = isUserInputValid(alphaString);
  17568.     var isBetaValid = isUserInputValid(betaString);
  17569.     var isGammaValid = isUserInputValid(gammaString);
  17570.  
  17571.     if (!isAlphaValid && !isBetaValid && !isGammaValid)
  17572.         return null;
  17573.  
  17574.     var alpha = isAlphaValid ? parseFloat(alphaString) : -1;
  17575.     var beta = isBetaValid ? parseFloat(betaString) : -1;
  17576.     var gamma = isGammaValid ? parseFloat(gammaString) : -1;
  17577.  
  17578.     return new WebInspector.UserAgentSupport.DeviceOrientation(alpha, beta, gamma);
  17579. }
  17580.  
  17581. WebInspector.UserAgentSupport.DeviceOrientation.clearDeviceOrientationOverride = function()
  17582. {
  17583.     PageAgent.clearDeviceOrientationOverride();
  17584. }
  17585.  
  17586. WebInspector.UserAgentSupport.prototype = {
  17587.     toggleUserAgentOverride: function(enabled)
  17588.     {
  17589.         if (enabled === this._userAgentOverrideEnabled)
  17590.             return;
  17591.         this._userAgentOverrideEnabled = enabled;
  17592.         this._userAgentChanged();
  17593.     },
  17594.  
  17595.     toggleDeviceMetricsOverride: function(enabled)
  17596.     {
  17597.         if (enabled === this._deviceMetricsOverrideEnabled)
  17598.             return;
  17599.         this._deviceMetricsOverrideEnabled = enabled;
  17600.         this._deviceMetricsChanged();
  17601.     },
  17602.  
  17603.     toggleGeolocationPositionOverride: function(enabled)
  17604.     {
  17605.         if (enabled === this._geolocationPositionOverrideEnabled)
  17606.             return;
  17607.         this._geolocationPositionOverrideEnabled = enabled;
  17608.         this._geolocationPositionChanged();
  17609.     },
  17610.  
  17611.     toggleDeviceOrientationOverride: function(enabled)
  17612.     {
  17613.         if (enabled === this._deviceOrientationOverrideEnabled)
  17614.             return;
  17615.         this._deviceOrientationOverrideEnabled = enabled;
  17616.         this._deviceOrientationChanged();
  17617.     },
  17618.  
  17619.     _userAgentChanged: function()
  17620.     {
  17621.         NetworkAgent.setUserAgentOverride(this._userAgentOverrideEnabled ? WebInspector.settings.userAgent.get() : "");
  17622.     },
  17623.  
  17624.     _deviceMetricsChanged: function()
  17625.     {
  17626.         var metrics = WebInspector.UserAgentSupport.DeviceMetrics.parseSetting(this._deviceMetricsOverrideEnabled ? WebInspector.settings.deviceMetrics.get() : "");
  17627.         if (metrics.isValid())
  17628.             PageAgent.setDeviceMetricsOverride(metrics.width, metrics.height, metrics.fontScaleFactor, WebInspector.settings.deviceFitWindow.get());
  17629.     },
  17630.  
  17631.     _geolocationPositionChanged: function()
  17632.     {
  17633.         if (!this._geolocationPositionOverrideEnabled) {
  17634.             PageAgent.clearGeolocationOverride();
  17635.             return;
  17636.         }
  17637.         var geolocation = WebInspector.UserAgentSupport.GeolocationPosition.parseSetting(WebInspector.settings.geolocationOverride.get());
  17638.         if (geolocation.error)
  17639.             PageAgent.setGeolocationOverride();
  17640.         else
  17641.             PageAgent.setGeolocationOverride(geolocation.latitude, geolocation.longitude, 150);
  17642.     },
  17643.  
  17644.     _deviceOrientationChanged: function()
  17645.     {
  17646.         if (!this._deviceOrientationOverrideEnabled) {
  17647.             PageAgent.clearDeviceOrientationOverride();
  17648.             return;
  17649.         }
  17650.         var deviceOrientation = WebInspector.UserAgentSupport.DeviceOrientation.parseSetting(WebInspector.settings.deviceOrientationOverride.get());
  17651.         PageAgent.setDeviceOrientationOverride(deviceOrientation.alpha, deviceOrientation.beta, deviceOrientation.gamma);
  17652.     }
  17653. }
  17654.  
  17655.  
  17656. /**
  17657.  * @type {WebInspector.UserAgentSupport} 
  17658.  */
  17659. WebInspector.userAgentSupport;
  17660.  
  17661. /* Database.js */
  17662.  
  17663. /*
  17664.  * Copyright (C) 2007, 2008 Apple Inc.  All rights reserved.
  17665.  *
  17666.  * Redistribution and use in source and binary forms, with or without
  17667.  * modification, are permitted provided that the following conditions
  17668.  * are met:
  17669.  *
  17670.  * 1.  Redistributions of source code must retain the above copyright
  17671.  *     notice, this list of conditions and the following disclaimer.
  17672.  * 2.  Redistributions in binary form must reproduce the above copyright
  17673.  *     notice, this list of conditions and the following disclaimer in the
  17674.  *     documentation and/or other materials provided with the distribution.
  17675.  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  17676.  *     its contributors may be used to endorse or promote products derived
  17677.  *     from this software without specific prior written permission.
  17678.  *
  17679.  * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
  17680.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17681.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17682.  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  17683.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  17684.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  17685.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  17686.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  17687.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  17688.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17689.  */
  17690.  
  17691. /**
  17692.  * @constructor
  17693.  * @param {WebInspector.DatabaseModel} model
  17694.  */
  17695. WebInspector.Database = function(model, id, domain, name, version)
  17696. {
  17697.     this._model = model;
  17698.     this._id = id;
  17699.     this._domain = domain;
  17700.     this._name = name;
  17701.     this._version = version;
  17702. }
  17703.  
  17704. WebInspector.Database.prototype = {
  17705.     /** @return {string} */
  17706.     get id()
  17707.     {
  17708.         return this._id;
  17709.     },
  17710.  
  17711.     /** @return {string} */
  17712.     get name()
  17713.     {
  17714.         return this._name;
  17715.     },
  17716.  
  17717.     set name(x)
  17718.     {
  17719.         this._name = x;
  17720.     },
  17721.  
  17722.     /** @return {string} */
  17723.     get version()
  17724.     {
  17725.         return this._version;
  17726.     },
  17727.  
  17728.     set version(x)
  17729.     {
  17730.         this._version = x;
  17731.     },
  17732.  
  17733.     /** @return {string} */
  17734.     get domain()
  17735.     {
  17736.         return this._domain;
  17737.     },
  17738.  
  17739.     set domain(x)
  17740.     {
  17741.         this._domain = x;
  17742.     },
  17743.  
  17744.     /**
  17745.      * @param {function(Array.<string>)} callback
  17746.      */
  17747.     getTableNames: function(callback)
  17748.     {
  17749.         function sortingCallback(error, names)
  17750.         {
  17751.             if (!error)
  17752.                 callback(names.sort());
  17753.         }
  17754.         DatabaseAgent.getDatabaseTableNames(this._id, sortingCallback);
  17755.     },
  17756.  
  17757.     /**
  17758.      * @param {string} query
  17759.      * @param {function(Array.<string>=, Array.<*>=)} onSuccess
  17760.      * @param {function(string)} onError
  17761.      */
  17762.     executeSql: function(query, onSuccess, onError)
  17763.     {
  17764.         /**
  17765.          * @param {?Protocol.Error} error
  17766.          * @param {Array.<string>=} columnNames
  17767.          * @param {Array.<*>=} values
  17768.          * @param {DatabaseAgent.Error=} errorObj
  17769.          */
  17770.         function callback(error, columnNames, values, errorObj)
  17771.         {
  17772.             if (error) {
  17773.                 onError(error);
  17774.                 return;
  17775.             }
  17776.             if (errorObj) {
  17777.                 var message;
  17778.                 if (errorObj.message)
  17779.                     message = errorObj.message;
  17780.                 else if (errorObj.code == 2)
  17781.                     message = WebInspector.UIString("Database no longer has expected version.");
  17782.                 else
  17783.                     message = WebInspector.UIString("An unexpected error %s occurred.", errorObj.code);
  17784.                 onError(message);
  17785.                 return;
  17786.             }
  17787.             onSuccess(columnNames, values);
  17788.         }
  17789.         DatabaseAgent.executeSQL(this._id, query, callback.bind(this));
  17790.     }
  17791. }
  17792.  
  17793. /**
  17794.  * @constructor
  17795.  * @extends {WebInspector.Object}
  17796.  */
  17797. WebInspector.DatabaseModel = function()
  17798. {
  17799.     this._databases = [];
  17800.     InspectorBackend.registerDatabaseDispatcher(new WebInspector.DatabaseDispatcher(this));
  17801.     DatabaseAgent.enable();
  17802. }
  17803.  
  17804. WebInspector.DatabaseModel.Events = {
  17805.     DatabaseAdded: "DatabaseAdded"
  17806. }
  17807.  
  17808. WebInspector.DatabaseModel.prototype = {
  17809.     /**
  17810.      * @return {Array.<WebInspector.Database>}
  17811.      */
  17812.     databases: function()
  17813.     {
  17814.         var result = [];
  17815.         for (var databaseId in this._databases)
  17816.             result.push(this._databases[databaseId]);
  17817.         return result;
  17818.     },
  17819.  
  17820.     /**
  17821.      * @param {DatabaseAgent.DatabaseId} databaseId
  17822.      * @return {WebInspector.Database}
  17823.      */
  17824.     databaseForId: function(databaseId)
  17825.     {
  17826.         return this._databases[databaseId];
  17827.     },
  17828.  
  17829.     /**
  17830.      * @param {WebInspector.Database} database
  17831.      */
  17832.     _addDatabase: function(database)
  17833.     {
  17834.         this._databases.push(database);
  17835.         this.dispatchEventToListeners(WebInspector.DatabaseModel.Events.DatabaseAdded, database);
  17836.     },
  17837.  
  17838.     __proto__: WebInspector.Object.prototype
  17839. }
  17840.  
  17841. /**
  17842.  * @constructor
  17843.  * @implements {DatabaseAgent.Dispatcher}
  17844.  * @param {WebInspector.DatabaseModel} model
  17845.  */
  17846. WebInspector.DatabaseDispatcher = function(model)
  17847. {
  17848.     this._model = model;
  17849. }
  17850.  
  17851. WebInspector.DatabaseDispatcher.prototype = {
  17852.     /**
  17853.      * @param {DatabaseAgent.Database} payload
  17854.      */
  17855.     addDatabase: function(payload)
  17856.     {
  17857.         this._model._addDatabase(new WebInspector.Database(
  17858.             this._model,
  17859.             payload.id,
  17860.             payload.domain,
  17861.             payload.name,
  17862.             payload.version));
  17863.     }
  17864. }
  17865.  
  17866. /**
  17867.  * @type {WebInspector.DatabaseModel}
  17868.  */
  17869. WebInspector.databaseModel = null;
  17870.  
  17871. /* DOMStorage.js */
  17872.  
  17873. /*
  17874.  * Copyright (C) 2008 Nokia Inc.  All rights reserved.
  17875.  *
  17876.  * Redistribution and use in source and binary forms, with or without
  17877.  * modification, are permitted provided that the following conditions
  17878.  * are met:
  17879.  *
  17880.  * 1.  Redistributions of source code must retain the above copyright
  17881.  *     notice, this list of conditions and the following disclaimer.
  17882.  * 2.  Redistributions in binary form must reproduce the above copyright
  17883.  *     notice, this list of conditions and the following disclaimer in the
  17884.  *     documentation and/or other materials provided with the distribution.
  17885.  * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
  17886.  *     its contributors may be used to endorse or promote products derived
  17887.  *     from this software without specific prior written permission.
  17888.  *
  17889.  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY
  17890.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17891.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17892.  * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
  17893.  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  17894.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  17895.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  17896.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  17897.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  17898.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  17899.  */
  17900.  
  17901. /**
  17902.  * @constructor
  17903.  */
  17904. WebInspector.DOMStorage = function(id, domain, isLocalStorage)
  17905. {
  17906.     this._id = id;
  17907.     this._domain = domain;
  17908.     this._isLocalStorage = isLocalStorage;
  17909. }
  17910.  
  17911. WebInspector.DOMStorage.prototype = {
  17912.     /** @return {string} */
  17913.     get id()
  17914.     {
  17915.         return this._id;
  17916.     },
  17917.  
  17918.     /** @return {string} */
  17919.     get domain()
  17920.     {
  17921.         return this._domain;
  17922.     },
  17923.  
  17924.     /** @return {boolean} */
  17925.     get isLocalStorage()
  17926.     {
  17927.         return this._isLocalStorage;
  17928.     },
  17929.  
  17930.     /**
  17931.      * @param {function(?Protocol.Error, Array.<DOMStorageAgent.Entry>):void=} callback
  17932.      */
  17933.     getEntries: function(callback)
  17934.     {
  17935.         DOMStorageAgent.getDOMStorageEntries(this._id, callback);
  17936.     },
  17937.  
  17938.     /**
  17939.      * @param {string} key
  17940.      * @param {string} value
  17941.      * @param {function(?Protocol.Error, boolean):void=} callback
  17942.      */
  17943.     setItem: function(key, value, callback)
  17944.     {
  17945.         DOMStorageAgent.setDOMStorageItem(this._id, key, value, callback);
  17946.     },
  17947.  
  17948.     /**
  17949.      * @param {string} key
  17950.      * @param {function(?Protocol.Error, boolean):void=} callback
  17951.      */
  17952.     removeItem: function(key, callback)
  17953.     {
  17954.         DOMStorageAgent.removeDOMStorageItem(this._id, key, callback);
  17955.     }
  17956. }
  17957.  
  17958. /**
  17959.  * @constructor
  17960.  * @extends {WebInspector.Object}
  17961.  */
  17962. WebInspector.DOMStorageModel = function()
  17963. {
  17964.     this._storages = {};
  17965.     InspectorBackend.registerDOMStorageDispatcher(new WebInspector.DOMStorageDispatcher(this));
  17966.     DOMStorageAgent.enable();
  17967. }
  17968.  
  17969. WebInspector.DOMStorageModel.Events = {
  17970.     DOMStorageAdded: "DOMStorageAdded",
  17971.     DOMStorageUpdated: "DOMStorageUpdated"
  17972. }
  17973.  
  17974. WebInspector.DOMStorageModel.prototype = {
  17975.     /**
  17976.      * @param {WebInspector.DOMStorage} domStorage
  17977.      */
  17978.     _addDOMStorage: function(domStorage)
  17979.     {
  17980.         this._storages[domStorage.id] = domStorage;
  17981.         this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageAdded, domStorage);
  17982.     },
  17983.  
  17984.     /**
  17985.      * @param {DOMStorageAgent.StorageId} storageId
  17986.      */
  17987.     _domStorageUpdated: function(storageId)
  17988.     {
  17989.         this.dispatchEventToListeners(WebInspector.DOMStorageModel.Events.DOMStorageUpdated, this._storages[storageId]);
  17990.     },
  17991.  
  17992.     /**
  17993.      * @param {DOMStorageAgent.StorageId} storageId
  17994.      * @return {WebInspector.DOMStorage}
  17995.      */
  17996.     storageForId: function(storageId)
  17997.     {
  17998.         return this._storages[storageId];
  17999.     },
  18000.  
  18001.     /**
  18002.      * @return {Array.<WebInspector.DOMStorage>}
  18003.      */
  18004.     storages: function()
  18005.     {
  18006.         var result = [];
  18007.         for (var storageId in this._storages)
  18008.             result.push(this._storages[storageId]);
  18009.         return result;
  18010.     },
  18011.  
  18012.     __proto__: WebInspector.Object.prototype
  18013. }
  18014.  
  18015. /**
  18016.  * @constructor
  18017.  * @implements {DOMStorageAgent.Dispatcher}
  18018.  * @param {WebInspector.DOMStorageModel} model
  18019.  */
  18020. WebInspector.DOMStorageDispatcher = function(model)
  18021. {
  18022.     this._model = model;
  18023. }
  18024.  
  18025. WebInspector.DOMStorageDispatcher.prototype = {
  18026.  
  18027.     /**
  18028.      * @param {DOMStorageAgent.Entry} payload
  18029.      */
  18030.     addDOMStorage: function(payload)
  18031.     {
  18032.         this._model._addDOMStorage(new WebInspector.DOMStorage(
  18033.             payload.id,
  18034.             payload.origin,
  18035.             payload.isLocalStorage));
  18036.     },
  18037.  
  18038.     /**
  18039.      * @param {string} storageId
  18040.      */
  18041.     domStorageUpdated: function(storageId)
  18042.     {
  18043.         this._model._domStorageUpdated(storageId);
  18044.     }
  18045. }
  18046.  
  18047. /**
  18048.  * @type {WebInspector.DOMStorageModel}
  18049.  */
  18050. WebInspector.domStorageModel = null;
  18051.  
  18052. /* DataGrid.js */
  18053.  
  18054. /*
  18055.  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
  18056.  *
  18057.  * Redistribution and use in source and binary forms, with or without
  18058.  * modification, are permitted provided that the following conditions
  18059.  * are met:
  18060.  * 1. Redistributions of source code must retain the above copyright
  18061.  *        notice, this list of conditions and the following disclaimer.
  18062.  * 2. Redistributions in binary form must reproduce the above copyright
  18063.  *        notice, this list of conditions and the following disclaimer in the
  18064.  *        documentation and/or other materials provided with the distribution.
  18065.  *
  18066.  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
  18067.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18068.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18069.  * PURPOSE ARE DISCLAIMED.         IN NO EVENT SHALL APPLE INC. OR
  18070.  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18071.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  18072.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  18073.  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  18074.  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  18075.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  18076.  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  18077.  */
  18078.  
  18079. /**
  18080.  * @constructor
  18081.  * @extends {WebInspector.View}
  18082.  * @param {function(WebInspector.DataGridNode, number, string, string)=} editCallback
  18083.  * @param {function(WebInspector.DataGridNode)=} deleteCallback
  18084.  */
  18085. WebInspector.DataGrid = function(columns, editCallback, deleteCallback)
  18086. {
  18087.     WebInspector.View.call(this);
  18088.     this.registerRequiredCSS("dataGrid.css");
  18089.  
  18090.     this.element.className = "data-grid";
  18091.     this.element.tabIndex = 0;
  18092.     this.element.addEventListener("keydown", this._keyDown.bind(this), false);
  18093.  
  18094.     this._headerTable = document.createElement("table");
  18095.     this._headerTable.className = "header";
  18096.     this._headerTableHeaders = {};
  18097.  
  18098.     this._dataTable = document.createElement("table");
  18099.     this._dataTable.className = "data";
  18100.  
  18101.     this._dataTable.addEventListener("mousedown", this._mouseDownInDataTable.bind(this), true);
  18102.     this._dataTable.addEventListener("click", this._clickInDataTable.bind(this), true);
  18103.  
  18104.     this._dataTable.addEventListener("contextmenu", this._contextMenuInDataTable.bind(this), true);
  18105.  
  18106.     // FIXME: Add a createCallback which is different from editCallback and has different
  18107.     // behavior when creating a new node.
  18108.     if (editCallback) {
  18109.         this._dataTable.addEventListener("dblclick", this._ondblclick.bind(this), false);
  18110.         this._editCallback = editCallback;
  18111.     }
  18112.     if (deleteCallback)
  18113.         this._deleteCallback = deleteCallback;
  18114.  
  18115.     this.aligned = {};
  18116.  
  18117.     this._scrollContainer = document.createElement("div");
  18118.     this._scrollContainer.className = "data-container";
  18119.     this._scrollContainer.appendChild(this._dataTable);
  18120.  
  18121.     this.element.appendChild(this._headerTable);
  18122.     this.element.appendChild(this._scrollContainer);
  18123.  
  18124.     var headerRow = document.createElement("tr");
  18125.     var columnGroup = document.createElement("colgroup");
  18126.     this._columnCount = 0;
  18127.  
  18128.     for (var columnIdentifier in columns) {
  18129.         var column = columns[columnIdentifier];
  18130.         if (column.disclosure)
  18131.             this.disclosureColumnIdentifier = columnIdentifier;
  18132.  
  18133.         var col = document.createElement("col");
  18134.         if (column.width)
  18135.             col.style.width = column.width;
  18136.         column.element = col;
  18137.         columnGroup.appendChild(col);
  18138.  
  18139.         var cell = document.createElement("th");
  18140.         cell.className = columnIdentifier + "-column";
  18141.         cell.columnIdentifier = columnIdentifier;
  18142.         this._headerTableHeaders[columnIdentifier] = cell;
  18143.  
  18144.         var div = document.createElement("div");
  18145.         if (column.titleDOMFragment)
  18146.             div.appendChild(column.titleDOMFragment);
  18147.         else
  18148.             div.textContent = column.title;
  18149.         cell.appendChild(div);
  18150.  
  18151.         if (column.sort) {
  18152.             cell.addStyleClass("sort-" + column.sort);
  18153.             this._sortColumnCell = cell;
  18154.         }
  18155.  
  18156.         if (column.sortable) {
  18157.             cell.addEventListener("click", this._clickInHeaderCell.bind(this), false);
  18158.             cell.addStyleClass("sortable");
  18159.         }
  18160.  
  18161.         if (column.aligned)
  18162.             this.aligned[columnIdentifier] = column.aligned;
  18163.  
  18164.         headerRow.appendChild(cell);
  18165.  
  18166.         ++this._columnCount;
  18167.     }
  18168.  
  18169.     columnGroup.span = this._columnCount;
  18170.  
  18171.     var cell = document.createElement("th");
  18172.     cell.className = "corner";
  18173.     headerRow.appendChild(cell);
  18174.  
  18175.     this._headerTableColumnGroup = columnGroup;
  18176.     this._headerTable.appendChild(this._headerTableColumnGroup);
  18177.     this.headerTableBody.appendChild(headerRow);
  18178.  
  18179.     var fillerRow = document.createElement("tr");
  18180.     fillerRow.className = "filler";
  18181.  
  18182.     for (var columnIdentifier in columns) {
  18183.         var column = columns[columnIdentifier];
  18184.         var td = document.createElement("td");
  18185.         td.className = columnIdentifier + "-column";
  18186.         fillerRow.appendChild(td);
  18187.     }
  18188.  
  18189.     this._dataTableColumnGroup = columnGroup.cloneNode(true);
  18190.     this._dataTable.appendChild(this._dataTableColumnGroup);
  18191.     this.dataTableBody.appendChild(fillerRow);
  18192.  
  18193.     this.columns = columns || {};
  18194.     this._columnsArray = [];
  18195.     for (var columnIdentifier in columns) {
  18196.         columns[columnIdentifier].ordinal = this._columnsArray.length;
  18197.         columns[columnIdentifier].identifier = columnIdentifier;
  18198.         this._columnsArray.push(columns[columnIdentifier]);
  18199.     }
  18200.  
  18201.     for (var i = 0; i < this._columnsArray.length; ++i)
  18202.         this._columnsArray[i].bodyElement = this._dataTableColumnGroup.children[i];
  18203.  
  18204.     this.selectedNode = null;
  18205.     this.expandNodesWhenArrowing = false;
  18206.     this.setRootNode(new WebInspector.DataGridNode());
  18207.     this.indentWidth = 15;
  18208.     this.resizers = [];
  18209.     this._columnWidthsInitialized = false;
  18210. }
  18211.  
  18212. WebInspector.DataGrid.Events = {
  18213.     SelectedNode: "SelectedNode",
  18214.     DeselectedNode: "DeselectedNode"
  18215. }
  18216.  
  18217. /**
  18218.  * @param {Array.<string>} columnNames
  18219.  * @param {Array.<string>} values
  18220.  */
  18221. WebInspector.DataGrid.createSortableDataGrid = function(columnNames, values)
  18222. {
  18223.     var numColumns = columnNames.length;
  18224.     if (!numColumns)
  18225.         return null;
  18226.  
  18227.     var columns = {};
  18228.  
  18229.     for (var i = 0; i < columnNames.length; ++i) {
  18230.         var column = {};
  18231.         column.width = columnNames[i].length;
  18232.         column.title = columnNames[i];
  18233.         column.sortable = true;
  18234.  
  18235.         columns[columnNames[i]] = column;
  18236.     }
  18237.  
  18238.     var nodes = [];
  18239.     for (var i = 0; i < values.length / numColumns; ++i) {
  18240.         var data = {};
  18241.         for (var j = 0; j < columnNames.length; ++j)
  18242.             data[columnNames[j]] = values[numColumns * i + j];
  18243.  
  18244.         var node = new WebInspector.DataGridNode(data, false);
  18245.         node.selectable = false;
  18246.         nodes.push(node);
  18247.     }
  18248.  
  18249.     var dataGrid = new WebInspector.DataGrid(columns);
  18250.     var length = nodes.length;
  18251.     for (var i = 0; i < length; ++i)
  18252.         dataGrid.rootNode().appendChild(nodes[i]);
  18253.  
  18254.     dataGrid.addEventListener("sorting changed", sortDataGrid, this);
  18255.  
  18256.     function sortDataGrid()
  18257.     {
  18258.         var nodes = dataGrid._rootNode.children.slice();
  18259.         var sortColumnIdentifier = dataGrid.sortColumnIdentifier;
  18260.         var sortDirection = dataGrid.sortOrder === "ascending" ? 1 : -1;
  18261.         var columnIsNumeric = true;
  18262.  
  18263.         for (var i = 0; i < nodes.length; i++) {
  18264.             if (isNaN(Number(nodes[i].data[sortColumnIdentifier])))
  18265.                 columnIsNumeric = false;
  18266.         }
  18267.  
  18268.         function comparator(dataGridNode1, dataGridNode2)
  18269.         {
  18270.             var item1 = dataGridNode1.data[sortColumnIdentifier];
  18271.             var item2 = dataGridNode2.data[sortColumnIdentifier];
  18272.  
  18273.             var comparison;
  18274.             if (columnIsNumeric) {
  18275.                 // Sort numbers based on comparing their values rather than a lexicographical comparison.
  18276.                 var number1 = parseFloat(item1);
  18277.                 var number2 = parseFloat(item2);
  18278.                 comparison = number1 < number2 ? -1 : (number1 > number2 ? 1 : 0);
  18279.             } else
  18280.                 comparison = item1 < item2 ? -1 : (item1 > item2 ? 1 : 0);
  18281.  
  18282.             return sortDirection * comparison;
  18283.         }
  18284.  
  18285.         nodes.sort(comparator);
  18286.         dataGrid.rootNode().removeChildren();
  18287.         for (var i = 0; i < nodes.length; i++)
  18288.             dataGrid._rootNode.appendChild(nodes[i]);
  18289.     }
  18290.     return dataGrid;
  18291. }
  18292.  
  18293. WebInspector.DataGrid.prototype = {
  18294.     setRootNode: function(rootNode)
  18295.     {
  18296.         if (this._rootNode) {
  18297.             this._rootNode.removeChildren();
  18298.             this._rootNode.dataGrid = null;
  18299.             this._rootNode._isRoot = false;
  18300.         }
  18301.         this._rootNode = rootNode;
  18302.         rootNode._isRoot = true;
  18303.         rootNode.hasChildren = false;
  18304.         rootNode._expanded = true;
  18305.         rootNode._revealed = true;
  18306.         rootNode.dataGrid = this;
  18307.     },
  18308.  
  18309.     rootNode: function()
  18310.     {
  18311.         return this._rootNode;
  18312.     },
  18313.  
  18314.     get refreshCallback()
  18315.     {
  18316.         return this._refreshCallback;
  18317.     },
  18318.  
  18319.     set refreshCallback(refreshCallback)
  18320.     {
  18321.         this._refreshCallback = refreshCallback;
  18322.     },
  18323.  
  18324.     _ondblclick: function(event)
  18325.     {
  18326.         if (this._editing || this._editingNode)
  18327.             return;
  18328.  
  18329.         this._startEditing(event.target);
  18330.     },
  18331.  
  18332.     _startEditingColumnOfDataGridNode: function(node, column)
  18333.     {
  18334.         this._editing = true;
  18335.         this._editingNode = node;
  18336.         this._editingNode.select();
  18337.  
  18338.         var element = this._editingNode._element.children[column];
  18339.         WebInspector.startEditing(element, this._startEditingConfig(element));
  18340.         window.getSelection().setBaseAndExtent(element, 0, element, 1);
  18341.     },
  18342.  
  18343.     _startEditing: function(target)
  18344.     {
  18345.         var element = target.enclosingNodeOrSelfWithNodeName("td");
  18346.         if (!element)
  18347.             return;
  18348.  
  18349.         this._editingNode = this.dataGridNodeFromNode(target);
  18350.         if (!this._editingNode) {
  18351.             if (!this.creationNode)
  18352.                 return;
  18353.             this._editingNode = this.creationNode;
  18354.         }
  18355.  
  18356.         // Force editing the 1st column when editing the creation node
  18357.         if (this._editingNode.isCreationNode)
  18358.             return this._startEditingColumnOfDataGridNode(this._editingNode, 0);
  18359.  
  18360.         this._editing = true;
  18361.         WebInspector.startEditing(element, this._startEditingConfig(element));
  18362.  
  18363.         window.getSelection().setBaseAndExtent(element, 0, element, 1);
  18364.     },
  18365.  
  18366.  
  18367.     _startEditingConfig: function(element)
  18368.     {
  18369.         return new WebInspector.EditingConfig(this._editingCommitted.bind(this), this._editingCancelled.bind(this), element.textContent);
  18370.     },
  18371.  
  18372.     _editingCommitted: function(element, newText, oldText, context, moveDirection)
  18373.     {
  18374.         // FIXME: We need more column identifiers here throughout this function.
  18375.         // Not needed yet since only editable DataGrid is DOM Storage, which is Key - Value.
  18376.  
  18377.         // FIXME: Better way to do this than regular expressions?
  18378.         var columnIdentifier = parseInt(element.className.match(/\b(\d+)-column\b/)[1], 10);
  18379.  
  18380.         var textBeforeEditing = this._editingNode.data[columnIdentifier];
  18381.         var currentEditingNode = this._editingNode;
  18382.  
  18383.         function moveToNextIfNeeded(wasChange) {
  18384.             if (!moveDirection)
  18385.                 return;
  18386.  
  18387.             if (moveDirection === "forward") {
  18388.                 if (currentEditingNode.isCreationNode && columnIdentifier === 0 && !wasChange)
  18389.                     return;
  18390.  
  18391.                 if (columnIdentifier === 0)
  18392.                     return this._startEditingColumnOfDataGridNode(currentEditingNode, 1);
  18393.  
  18394.                 var nextDataGridNode = currentEditingNode.traverseNextNode(true, null, true);
  18395.                 if (nextDataGridNode)
  18396.                     return this._startEditingColumnOfDataGridNode(nextDataGridNode, 0);
  18397.                 if (currentEditingNode.isCreationNode && wasChange) {
  18398.                     this.addCreationNode(false);
  18399.                     return this._startEditingColumnOfDataGridNode(this.creationNode, 0);
  18400.                 }
  18401.                 return;
  18402.             }
  18403.  
  18404.             if (moveDirection === "backward") {
  18405.                 if (columnIdentifier === 1)
  18406.                     return this._startEditingColumnOfDataGridNode(currentEditingNode, 0);
  18407.                     var nextDataGridNode = currentEditingNode.traversePreviousNode(true, null, true);
  18408.  
  18409.                 if (nextDataGridNode)
  18410.                     return this._startEditingColumnOfDataGridNode(nextDataGridNode, 1);
  18411.                 return;
  18412.             }
  18413.         }
  18414.  
  18415.         if (textBeforeEditing == newText) {
  18416.             this._editingCancelled(element);
  18417.             moveToNextIfNeeded.call(this, false);
  18418.             return;
  18419.         }
  18420.  
  18421.         // Update the text in the datagrid that we typed
  18422.         this._editingNode.data[columnIdentifier] = newText;
  18423.  
  18424.         // Make the callback - expects an editing node (table row), the column number that is being edited,
  18425.         // the text that used to be there, and the new text.
  18426.         this._editCallback(this._editingNode, columnIdentifier, textBeforeEditing, newText);
  18427.  
  18428.         if (this._editingNode.isCreationNode)
  18429.             this.addCreationNode(false);
  18430.  
  18431.         this._editingCancelled(element);
  18432.         moveToNextIfNeeded.call(this, true);
  18433.     },
  18434.  
  18435.     _editingCancelled: function(element)
  18436.     {
  18437.         delete this._editing;
  18438.         this._editingNode = null;
  18439.     },
  18440.  
  18441.     /**
  18442.      * @return {?string}
  18443.      */
  18444.     get sortColumnIdentifier()
  18445.     {
  18446.         if (!this._sortColumnCell)
  18447.             return null;
  18448.         return this._sortColumnCell.columnIdentifier;
  18449.     },
  18450.  
  18451.     /**
  18452.      * @return {?string}
  18453.      */
  18454.     get sortOrder()
  18455.     {
  18456.         if (!this._sortColumnCell || this._sortColumnCell.hasStyleClass("sort-ascending"))
  18457.             return "ascending";
  18458.         if (this._sortColumnCell.hasStyleClass("sort-descending"))
  18459.             return "descending";
  18460.         return null;
  18461.     },
  18462.  
  18463.     get headerTableBody()
  18464.     {
  18465.         if ("_headerTableBody" in this)
  18466.             return this._headerTableBody;
  18467.  
  18468.         this._headerTableBody = this._headerTable.getElementsByTagName("tbody")[0];
  18469.         if (!this._headerTableBody) {
  18470.             this._headerTableBody = this.element.ownerDocument.createElement("tbody");
  18471.             this._headerTable.insertBefore(this._headerTableBody, this._headerTable.tFoot);
  18472.         }
  18473.  
  18474.         return this._headerTableBody;
  18475.     },
  18476.  
  18477.     get dataTableBody()
  18478.     {
  18479.         if ("_dataTableBody" in this)
  18480.             return this._dataTableBody;
  18481.  
  18482.         this._dataTableBody = this._dataTable.getElementsByTagName("tbody")[0];
  18483.         if (!this._dataTableBody) {
  18484.             this._dataTableBody = this.element.ownerDocument.createElement("tbody");
  18485.             this._dataTable.insertBefore(this._dataTableBody, this._dataTable.tFoot);
  18486.         }
  18487.  
  18488.         return this._dataTableBody;
  18489.     },
  18490.  
  18491.     /**
  18492.      * @param {Array.<number>} widths
  18493.      * @param {number} minPercent
  18494.      * @param {number=} maxPercent
  18495.      */
  18496.     _autoSizeWidths: function(widths, minPercent, maxPercent)
  18497.     {
  18498.         if (minPercent)
  18499.             minPercent = Math.min(minPercent, Math.floor(100 / widths.length));
  18500.         var totalWidth = 0;
  18501.         for (var i = 0; i < widths.length; ++i)
  18502.             totalWidth += widths[i];
  18503.         var totalPercentWidth = 0;
  18504.         for (var i = 0; i < widths.length; ++i) {
  18505.             var width = Math.round(100 * widths[i] / totalWidth);
  18506.             if (minPercent && width < minPercent)
  18507.                 width = minPercent;
  18508.             else if (maxPercent && width > maxPercent)
  18509.                 width = maxPercent;
  18510.             totalPercentWidth += width;
  18511.             widths[i] = width;
  18512.         }
  18513.         var recoupPercent = totalPercentWidth - 100;
  18514.  
  18515.         while (minPercent && recoupPercent > 0) {
  18516.             for (var i = 0; i < widths.length; ++i) {
  18517.                 if (widths[i] > minPercent) {
  18518.                     --widths[i];
  18519.                     --recoupPercent;
  18520.                     if (!recoupPercent)
  18521.                         break;
  18522.                 }
  18523.             }
  18524.         }
  18525.  
  18526.         while (maxPercent && recoupPercent < 0) {
  18527.             for (var i = 0; i < widths.length; ++i) {
  18528.                 if (widths[i] < maxPercent) {
  18529.                     ++widths[i];
  18530.                     ++recoupPercent;
  18531.                     if (!recoupPercent)
  18532.                         break;
  18533.                 }
  18534.             }
  18535.         }
  18536.  
  18537.         return widths;
  18538.     },
  18539.  
  18540.     /**
  18541.      * @param {number} minPercent
  18542.      * @param {number=} maxPercent
  18543.      * @param {number=} maxDescentLevel
  18544.      */
  18545.     autoSizeColumns: function(minPercent, maxPercent, maxDescentLevel)
  18546.     {
  18547.         var widths = [];
  18548.         var columnIdentifiers = Object.keys(this.columns);
  18549.         for (var i = 0; i < columnIdentifiers.length; ++i)
  18550.             widths[i] = (this.columns[columnIdentifiers[i]].title || "").length;
  18551.  
  18552.         maxDescentLevel = maxDescentLevel || 0;
  18553.         var children = this._enumerateChildren(this._rootNode, [], maxDescentLevel + 1);
  18554.         for (var i = 0; i < children.length; ++i) {
  18555.             var node = children[i];
  18556.             for (var j = 0; j < columnIdentifiers.length; ++j) {
  18557.                 var text = node.data[columnIdentifiers[j]] || "";
  18558.                 if (text.length > widths[j])
  18559.                     widths[j] = text.length;
  18560.             }
  18561.         }
  18562.  
  18563.         widths = this._autoSizeWidths(widths, minPercent, maxPercent);
  18564.  
  18565.         for (var i = 0; i < columnIdentifiers.length; ++i)
  18566.             this.columns[columnIdentifiers[i]].element.style.width = widths[i] + "%";
  18567.         this._columnWidthsInitialized = false;
  18568.         this.updateWidths();
  18569.     },
  18570.  
  18571.     _enumerateChildren: function(rootNode, result, maxLevel)
  18572.     {
  18573.         if (!rootNode._isRoot)
  18574.             result.push(rootNode);
  18575.         if (!maxLevel)
  18576.             return;
  18577.         for (var i = 0; i < rootNode.children.length; ++i)
  18578.             this._enumerateChildren(rootNode.children[i], result, maxLevel - 1);
  18579.         return result;
  18580.     },
  18581.  
  18582.     onResize: function()
  18583.     {
  18584.         this.updateWidths();
  18585.     },
  18586.  
  18587.     // Updates the widths of the table, including the positions of the column
  18588.     // resizers.
  18589.     //
  18590.     // IMPORTANT: This function MUST be called once after the element of the
  18591.     // DataGrid is attached to its parent element and every subsequent time the
  18592.     // width of the parent element is changed in order to make it possible to
  18593.     // resize the columns.
  18594.     //
  18595.     // If this function is not called after the DataGrid is attached to its
  18596.     // parent element, then the DataGrid's columns will not be resizable.
  18597. updateWidths: function()
  18598. {
  18599. var headerTableColumns = this._headerTableColumnGroup.children;
  18600.  
  18601. var tableWidth = this._dataTable.offsetWidth;
  18602. var numColumns = headerTableColumns.length;
  18603.  
  18604.  
  18605. if (!this._columnWidthsInitialized && this.element.offsetWidth) {
  18606.  
  18607.  
  18608.  
  18609.  
  18610. for (var i = 0; i < numColumns; i++) {
  18611. var columnWidth = this.headerTableBody.rows[0].cells[i].offsetWidth;
  18612. var percentWidth = ((columnWidth / tableWidth) * 100) + "%";
  18613. this._headerTableColumnGroup.children[i].style.width = percentWidth;
  18614. this._dataTableColumnGroup.children[i].style.width = percentWidth;
  18615. }
  18616. this._columnWidthsInitialized = true;
  18617. }
  18618. this._positionResizers();
  18619. this.dispatchEventToListeners("width changed");
  18620. },
  18621.  
  18622. columnWidthsMap: function()
  18623. {
  18624. var result = {};
  18625. for (var i = 0; i < this._columnsArray.length; ++i) {
  18626. var width = this._headerTableColumnGroup.children[i].style.width;
  18627. result[this._columnsArray[i].columnIdentifier] = parseFloat(width);
  18628. }
  18629. return result;
  18630. },
  18631.  
  18632. applyColumnWidthsMap: function(columnWidthsMap)
  18633. {
  18634. for (var columnIdentifier in this.columns) {
  18635. var column = this.columns[columnIdentifier];
  18636. var width = (columnWidthsMap[columnIdentifier] || 0) + "%";
  18637. this._headerTableColumnGroup.children[column.ordinal].style.width = width;
  18638. this._dataTableColumnGroup.children[column.ordinal].style.width = width;
  18639. }
  18640.  
  18641.  
  18642. delete this._columnWidthsInitialized;
  18643. this.updateWidths();
  18644. },
  18645.  
  18646. isColumnVisible: function(columnIdentifier)
  18647. {
  18648. var column = this.columns[columnIdentifier];
  18649. var columnElement = column.element;
  18650. return !columnElement.hidden;
  18651. },
  18652.  
  18653. showColumn: function(columnIdentifier)
  18654. {
  18655. var column = this.columns[columnIdentifier];
  18656. var columnElement = column.element;
  18657. if (!columnElement.hidden)
  18658. return;
  18659.  
  18660. columnElement.hidden = false;
  18661. columnElement.removeStyleClass("hidden");
  18662.  
  18663. var columnBodyElement = column.bodyElement;
  18664. columnBodyElement.hidden = false;
  18665. columnBodyElement.removeStyleClass("hidden");
  18666. },
  18667.  
  18668. hideColumn: function(columnIdentifier)
  18669. {
  18670. var column = this.columns[columnIdentifier];
  18671. var columnElement = column.element;
  18672. if (columnElement.hidden)
  18673. return;
  18674.  
  18675. var oldWidth = parseFloat(columnElement.style.width);
  18676.  
  18677. columnElement.hidden = true;
  18678. columnElement.addStyleClass("hidden");
  18679. columnElement.style.width = 0;
  18680.  
  18681. var columnBodyElement = column.bodyElement;
  18682. columnBodyElement.hidden = true;
  18683. columnBodyElement.addStyleClass("hidden");
  18684. columnBodyElement.style.width = 0;
  18685.  
  18686. this._columnWidthsInitialized = false;
  18687. },
  18688.  
  18689. get scrollContainer()
  18690. {
  18691. return this._scrollContainer;
  18692. },
  18693.  
  18694. isScrolledToLastRow: function()
  18695. {
  18696. return this._scrollContainer.isScrolledToBottom();
  18697. },
  18698.  
  18699. scrollToLastRow: function()
  18700. {
  18701. this._scrollContainer.scrollTop = this._scrollContainer.scrollHeight - this._scrollContainer.offsetHeight;
  18702. },
  18703.  
  18704. _positionResizers: function()
  18705. {
  18706. var headerTableColumns = this._headerTableColumnGroup.children;
  18707. var numColumns = headerTableColumns.length;
  18708. var left = 0;
  18709. var previousResizer = null;
  18710.  
  18711.  
  18712. for (var i = 0; i < numColumns - 1; i++) {
  18713. var resizer = this.resizers[i];
  18714.  
  18715. if (!resizer) {
  18716.  
  18717.  
  18718. resizer = document.createElement("div");
  18719. resizer.addStyleClass("data-grid-resizer");
  18720.  
  18721. WebInspector.installDragHandle(resizer, this._startResizerDragging.bind(this), this._resizerDragging.bind(this), this._endResizerDragging.bind(this), "col-resize");
  18722. this.element.appendChild(resizer);
  18723. this.resizers[i] = resizer;
  18724. }
  18725.  
  18726.  
  18727.  
  18728.  
  18729. left += this.headerTableBody.rows[0].cells[i].offsetWidth;
  18730.  
  18731. var columnIsVisible = !this._headerTableColumnGroup.children[i].hidden;
  18732. if (columnIsVisible) {
  18733. resizer.style.removeProperty("display");
  18734. resizer.style.left = left + "px";
  18735. resizer.leftNeighboringColumnID = i;
  18736. if (previousResizer)
  18737. previousResizer.rightNeighboringColumnID = i;
  18738. previousResizer = resizer;
  18739. } else {
  18740. resizer.style.setProperty("display", "none");
  18741. resizer.leftNeighboringColumnID = 0;
  18742. resizer.rightNeighboringColumnID = 0;
  18743. }
  18744. }
  18745. if (previousResizer)
  18746. previousResizer.rightNeighboringColumnID = numColumns - 1;
  18747. },
  18748.  
  18749. addCreationNode: function(hasChildren)
  18750. {
  18751. if (this.creationNode)
  18752. this.creationNode.makeNormal();
  18753.  
  18754. var emptyData = {};
  18755. for (var column in this.columns)
  18756. emptyData[column] = '';
  18757. this.creationNode = new WebInspector.CreationDataGridNode(emptyData, hasChildren);
  18758. this.rootNode().appendChild(this.creationNode);
  18759. },
  18760.  
  18761. sortNodes: function(comparator, reverseMode)
  18762. {
  18763. function comparatorWrapper(a, b)
  18764. {
  18765. if (a._dataGridNode._data.summaryRow)
  18766. return 1;
  18767. if (b._dataGridNode._data.summaryRow)
  18768. return -1;
  18769.  
  18770. var aDataGirdNode = a._dataGridNode;
  18771. var bDataGirdNode = b._dataGridNode;
  18772. return reverseMode ? comparator(bDataGirdNode, aDataGirdNode) : comparator(aDataGirdNode, bDataGirdNode);
  18773. }
  18774.  
  18775. var tbody = this.dataTableBody;
  18776. var tbodyParent = tbody.parentElement;
  18777. tbodyParent.removeChild(tbody);
  18778.  
  18779. var childNodes = tbody.childNodes;
  18780. var fillerRow = childNodes[childNodes.length - 1];
  18781.  
  18782. var sortedRows = Array.prototype.slice.call(childNodes, 0, childNodes.length - 1);
  18783. sortedRows.sort(comparatorWrapper);
  18784. var sortedRowsLength = sortedRows.length;
  18785.  
  18786. tbody.removeChildren();
  18787. var previousSiblingNode = null;
  18788. for (var i = 0; i < sortedRowsLength; ++i) {
  18789. var row = sortedRows[i];
  18790. var node = row._dataGridNode;
  18791. node.previousSibling = previousSiblingNode;
  18792. if (previousSiblingNode)
  18793. previousSiblingNode.nextSibling = node;
  18794. tbody.appendChild(row);
  18795. previousSiblingNode = node;
  18796. }
  18797. if (previousSiblingNode)
  18798. previousSiblingNode.nextSibling = null;
  18799.  
  18800. tbody.appendChild(fillerRow);
  18801. tbodyParent.appendChild(tbody);
  18802. },
  18803.  
  18804. _keyDown: function(event)
  18805. {
  18806. if (!this.selectedNode || event.shiftKey || event.metaKey || event.ctrlKey || this._editing)
  18807. return;
  18808.  
  18809. var handled = false;
  18810. var nextSelectedNode;
  18811. if (event.keyIdentifier === "Up" && !event.altKey) {
  18812. nextSelectedNode = this.selectedNode.traversePreviousNode(true);
  18813. while (nextSelectedNode && !nextSelectedNode.selectable)
  18814. nextSelectedNode = nextSelectedNode.traversePreviousNode(true);
  18815. handled = nextSelectedNode ? true : false;
  18816. } else if (event.keyIdentifier === "Down" && !event.altKey) {
  18817. nextSelectedNode = this.selectedNode.traverseNextNode(true);
  18818. while (nextSelectedNode && !nextSelectedNode.selectable)
  18819. nextSelectedNode = nextSelectedNode.traverseNextNode(true);
  18820. handled = nextSelectedNode ? true : false;
  18821. } else if (event.keyIdentifier === "Left") {
  18822. if (this.selectedNode.expanded) {
  18823. if (event.altKey)
  18824. this.selectedNode.collapseRecursively();
  18825. else
  18826. this.selectedNode.collapse();
  18827. handled = true;
  18828. } else if (this.selectedNode.parent && !this.selectedNode.parent._isRoot) {
  18829. handled = true;
  18830. if (this.selectedNode.parent.selectable) {
  18831. nextSelectedNode = this.selectedNode.parent;
  18832. handled = nextSelectedNode ? true : false;
  18833. } else if (this.selectedNode.parent)
  18834. this.selectedNode.parent.collapse();
  18835. }
  18836. } else if (event.keyIdentifier === "Right") {
  18837. if (!this.selectedNode.revealed) {
  18838. this.selectedNode.reveal();
  18839. handled = true;
  18840. } else if (this.selectedNode.hasChildren) {
  18841. handled = true;
  18842. if (this.selectedNode.expanded) {
  18843. nextSelectedNode = this.selectedNode.children[0];
  18844. handled = nextSelectedNode ? true : false;
  18845. } else {
  18846. if (event.altKey)
  18847. this.selectedNode.expandRecursively();
  18848. else
  18849. this.selectedNode.expand();
  18850. }
  18851. }
  18852. } else if (event.keyCode === 8 || event.keyCode === 46) {
  18853. if (this._deleteCallback) {
  18854. handled = true;
  18855. this._deleteCallback(this.selectedNode);
  18856. }
  18857. } else if (isEnterKey(event)) {
  18858. if (this._editCallback) {
  18859. handled = true;
  18860.  
  18861.  
  18862. this._startEditing(this.selectedNode._element.children[0]);
  18863. }
  18864. }
  18865.  
  18866. if (nextSelectedNode) {
  18867. nextSelectedNode.reveal();
  18868. nextSelectedNode.select();
  18869. }
  18870.  
  18871. if (handled)
  18872. event.consume(true);
  18873. },
  18874.  
  18875. dataGridNodeFromNode: function(target)
  18876. {
  18877. var rowElement = target.enclosingNodeOrSelfWithNodeName("tr");
  18878. return rowElement && rowElement._dataGridNode;
  18879. },
  18880.  
  18881. dataGridNodeFromPoint: function(x, y)
  18882. {
  18883. var node = this._dataTable.ownerDocument.elementFromPoint(x, y);
  18884. var rowElement = node.enclosingNodeOrSelfWithNodeName("tr");
  18885. return rowElement && rowElement._dataGridNode;
  18886. },
  18887.  
  18888. _clickInHeaderCell: function(event)
  18889. {
  18890. var cell = event.target.enclosingNodeOrSelfWithNodeName("th");
  18891. if (!cell || !cell.columnIdentifier || !cell.hasStyleClass("sortable"))
  18892. return;
  18893.  
  18894. var sortOrder = this.sortOrder;
  18895.  
  18896. if (this._sortColumnCell)
  18897. this._sortColumnCell.removeMatchingStyleClasses("sort-\\w+");
  18898.  
  18899. if (cell == this._sortColumnCell) {
  18900. if (sortOrder === "ascending")
  18901. sortOrder = "descending";
  18902. else
  18903. sortOrder = "ascending";
  18904. }
  18905.  
  18906. this._sortColumnCell = cell;
  18907.  
  18908. cell.addStyleClass("sort-" + sortOrder);
  18909.  
  18910. this.dispatchEventToListeners("sorting changed");
  18911. },
  18912.  
  18913. markColumnAsSortedBy: function(columnIdentifier, sortOrder)
  18914. {
  18915. if (this._sortColumnCell)
  18916. this._sortColumnCell.removeMatchingStyleClasses("sort-\\w+");
  18917. this._sortColumnCell = this._headerTableHeaders[columnIdentifier];
  18918. this._sortColumnCell.addStyleClass("sort-" + sortOrder);
  18919. },
  18920.  
  18921. headerTableHeader: function(columnIdentifier)
  18922. {
  18923. return this._headerTableHeaders[columnIdentifier];
  18924. },
  18925.  
  18926. _mouseDownInDataTable: function(event)
  18927. {
  18928. var gridNode = this.dataGridNodeFromNode(event.target);
  18929. if (!gridNode || !gridNode.selectable)
  18930. return;
  18931.  
  18932. if (gridNode.isEventWithinDisclosureTriangle(event))
  18933. return;
  18934.  
  18935. if (event.metaKey) {
  18936. if (gridNode.selected)
  18937. gridNode.deselect();
  18938. else
  18939. gridNode.select();
  18940. } else
  18941. gridNode.select();
  18942. },
  18943.  
  18944. _contextMenuInDataTable: function(event)
  18945. {
  18946. var contextMenu = new WebInspector.ContextMenu(event);
  18947.  
  18948. var gridNode = this.dataGridNodeFromNode(event.target);
  18949. if (this._refreshCallback && (!gridNode || gridNode !== this.creationNode))
  18950. contextMenu.appendItem(WebInspector.UIString("Refresh"), this._refreshCallback.bind(this));
  18951.  
  18952. if (gridNode && gridNode.selectable && !gridNode.isEventWithinDisclosureTriangle(event)) {
  18953.  
  18954. if (this._editCallback) {
  18955. if (gridNode === this.creationNode)
  18956. contextMenu.appendItem(WebInspector.UIString("Add New"), this._startEditing.bind(this, event.target));
  18957. else
  18958. contextMenu.appendItem(WebInspector.UIString("Edit"), this._startEditing.bind(this, event.target));
  18959. }
  18960. if (this._deleteCallback && gridNode !== this.creationNode)
  18961. contextMenu.appendItem(WebInspector.UIString("Delete"), this._deleteCallback.bind(this, gridNode));
  18962. }
  18963.  
  18964. contextMenu.show();
  18965. },
  18966.  
  18967. _clickInDataTable: function(event)
  18968. {
  18969. var gridNode = this.dataGridNodeFromNode(event.target);
  18970. if (!gridNode || !gridNode.hasChildren)
  18971. return;
  18972.  
  18973. if (!gridNode.isEventWithinDisclosureTriangle(event))
  18974. return;
  18975.  
  18976. if (gridNode.expanded) {
  18977. if (event.altKey)
  18978. gridNode.collapseRecursively();
  18979. else
  18980. gridNode.collapse();
  18981. } else {
  18982. if (event.altKey)
  18983. gridNode.expandRecursively();
  18984. else
  18985. gridNode.expand();
  18986. }
  18987. },
  18988.  
  18989. get resizeMethod()
  18990. {
  18991. if (typeof this._resizeMethod === "undefined")
  18992. return WebInspector.DataGrid.ResizeMethod.Nearest;
  18993. return this._resizeMethod;
  18994. },
  18995.  
  18996. set resizeMethod(method)
  18997. {
  18998. this._resizeMethod = method;
  18999. },
  19000.  
  19001.  
  19002. _startResizerDragging: function(event)
  19003. {
  19004. this._currentResizer = event.target;
  19005. return !!this._currentResizer.rightNeighboringColumnID
  19006. },
  19007.  
  19008. _resizerDragging: function(event)
  19009. {
  19010. var resizer = this._currentResizer;
  19011. if (!resizer)
  19012. return;
  19013.  
  19014.  
  19015.  
  19016. var dragPoint = event.clientX - this.element.totalOffsetLeft();
  19017.  
  19018.  
  19019. var leftCellIndex = resizer.leftNeighboringColumnID;
  19020. var rightCellIndex = resizer.rightNeighboringColumnID;
  19021. var firstRowCells = this.headerTableBody.rows[0].cells;
  19022. var leftEdgeOfPreviousColumn = 0;
  19023. for (var i = 0; i < leftCellIndex; i++)
  19024. leftEdgeOfPreviousColumn += firstRowCells[i].offsetWidth;
  19025.  
  19026.  
  19027. if (this.resizeMethod == WebInspector.DataGrid.ResizeMethod.Last) {
  19028. rightCellIndex = this.resizers.length;
  19029. } else if (this.resizeMethod == WebInspector.DataGrid.ResizeMethod.First) {
  19030. leftEdgeOfPreviousColumn += firstRowCells[leftCellIndex].offsetWidth - firstRowCells[0].offsetWidth;
  19031. leftCellIndex = 0;
  19032. }
  19033.  
  19034. var rightEdgeOfNextColumn = leftEdgeOfPreviousColumn + firstRowCells[leftCellIndex].offsetWidth + firstRowCells[rightCellIndex].offsetWidth;
  19035.  
  19036.  
  19037. var leftMinimum = leftEdgeOfPreviousColumn + this.ColumnResizePadding;
  19038. var rightMaximum = rightEdgeOfNextColumn - this.ColumnResizePadding;
  19039.  
  19040. dragPoint = Number.constrain(dragPoint, leftMinimum, rightMaximum);
  19041.  
  19042. resizer.style.left = (dragPoint - this.CenterResizerOverBorderAdjustment) + "px";
  19043.  
  19044. var percentLeftColumn = (((dragPoint - leftEdgeOfPreviousColumn) / this._dataTable.offsetWidth) * 100) + "%";
  19045. this._headerTableColumnGroup.children[leftCellIndex].style.width = percentLeftColumn;
  19046. this._dataTableColumnGroup.children[leftCellIndex].style.width = percentLeftColumn;
  19047.  
  19048. var percentRightColumn = (((rightEdgeOfNextColumn - dragPoint) / this._dataTable.offsetWidth) * 100) + "%";
  19049. this._headerTableColumnGroup.children[rightCellIndex].style.width =  percentRightColumn;
  19050. this._dataTableColumnGroup.children[rightCellIndex].style.width = percentRightColumn;
  19051.  
  19052. this._positionResizers();
  19053. event.preventDefault();
  19054. this.dispatchEventToListeners("width changed");
  19055. },
  19056.  
  19057. _endResizerDragging: function(event)
  19058. {
  19059. this._currentResizer = null;
  19060. this.dispatchEventToListeners("width changed");
  19061. },
  19062.  
  19063. ColumnResizePadding: 10,
  19064.  
  19065. CenterResizerOverBorderAdjustment: 3,
  19066.  
  19067. __proto__: WebInspector.View.prototype
  19068. }
  19069.  
  19070. WebInspector.DataGrid.ResizeMethod = {
  19071. Nearest: "nearest",
  19072. First: "first",
  19073. Last: "last"
  19074. }
  19075.  
  19076.  
  19077. WebInspector.DataGridNode = function(data, hasChildren)
  19078. {
  19079. this._expanded = false;
  19080. this._selected = false;
  19081. this._shouldRefreshChildren = true;
  19082. this._data = data || {};
  19083. this.hasChildren = hasChildren || false;
  19084. this.children = [];
  19085. this.dataGrid = null;
  19086. this.parent = null;
  19087. this.previousSibling = null;
  19088. this.nextSibling = null;
  19089. this.disclosureToggleWidth = 10;
  19090. }
  19091.  
  19092. WebInspector.DataGridNode.prototype = {
  19093. selectable: true,
  19094.  
  19095. _isRoot: false,
  19096.  
  19097. get element()
  19098. {
  19099. if (this._element)
  19100. return this._element;
  19101.  
  19102. if (!this.dataGrid)
  19103. return null;
  19104.  
  19105. this._element = document.createElement("tr");
  19106. this._element._dataGridNode = this;
  19107.  
  19108. if (this.hasChildren)
  19109. this._element.addStyleClass("parent");
  19110. if (this.expanded)
  19111. this._element.addStyleClass("expanded");
  19112. if (this.selected)
  19113. this._element.addStyleClass("selected");
  19114. if (this.revealed)
  19115. this._element.addStyleClass("revealed");
  19116.  
  19117. this.createCells();
  19118. return this._element;
  19119. },
  19120.  
  19121. createCells: function()
  19122. {
  19123. for (var columnIdentifier in this.dataGrid.columns) {
  19124. var cell = this.createCell(columnIdentifier);
  19125. this._element.appendChild(cell);
  19126. }
  19127. },
  19128.  
  19129. get data()
  19130. {
  19131. return this._data;
  19132. },
  19133.  
  19134. set data(x)
  19135. {
  19136. this._data = x || {};
  19137. this.refresh();
  19138. },
  19139.  
  19140. get revealed()
  19141. {
  19142. if ("_revealed" in this)
  19143. return this._revealed;
  19144.  
  19145. var currentAncestor = this.parent;
  19146. while (currentAncestor && !currentAncestor._isRoot) {
  19147. if (!currentAncestor.expanded) {
  19148. this._revealed = false;
  19149. return false;
  19150. }
  19151.  
  19152. currentAncestor = currentAncestor.parent;
  19153. }
  19154.  
  19155. this._revealed = true;
  19156. return true;
  19157. },
  19158.  
  19159. set hasChildren(x)
  19160. {
  19161. if (this._hasChildren === x)
  19162. return;
  19163.  
  19164. this._hasChildren = x;
  19165.  
  19166. if (!this._element)
  19167. return;
  19168.  
  19169. if (this._hasChildren)
  19170. {
  19171. this._element.addStyleClass("parent");
  19172. if (this.expanded)
  19173. this._element.addStyleClass("expanded");
  19174. }
  19175. else
  19176. {
  19177. this._element.removeStyleClass("parent");
  19178. this._element.removeStyleClass("expanded");
  19179. }
  19180. },
  19181.  
  19182. get hasChildren()
  19183. {
  19184. return this._hasChildren;
  19185. },
  19186.  
  19187. set revealed(x)
  19188. {
  19189. if (this._revealed === x)
  19190. return;
  19191.  
  19192. this._revealed = x;
  19193.  
  19194. if (this._element) {
  19195. if (this._revealed)
  19196. this._element.addStyleClass("revealed");
  19197. else
  19198. this._element.removeStyleClass("revealed");
  19199. }
  19200.  
  19201. for (var i = 0; i < this.children.length; ++i)
  19202. this.children[i].revealed = x && this.expanded;
  19203. },
  19204.  
  19205. get depth()
  19206. {
  19207. if ("_depth" in this)
  19208. return this._depth;
  19209. if (this.parent && !this.parent._isRoot)
  19210. this._depth = this.parent.depth + 1;
  19211. else
  19212. this._depth = 0;
  19213. return this._depth;
  19214. },
  19215.  
  19216. get leftPadding()
  19217. {
  19218. if (typeof(this._leftPadding) === "number")
  19219. return this._leftPadding;
  19220.  
  19221. this._leftPadding = this.depth * this.dataGrid.indentWidth;
  19222. return this._leftPadding;
  19223. },
  19224.  
  19225. get shouldRefreshChildren()
  19226. {
  19227. return this._shouldRefreshChildren;
  19228. },
  19229.  
  19230. set shouldRefreshChildren(x)
  19231. {
  19232. this._shouldRefreshChildren = x;
  19233. if (x && this.expanded)
  19234. this.expand();
  19235. },
  19236.  
  19237. get selected()
  19238. {
  19239. return this._selected;
  19240. },
  19241.  
  19242. set selected(x)
  19243. {
  19244. if (x)
  19245. this.select();
  19246. else
  19247. this.deselect();
  19248. },
  19249.  
  19250. get expanded()
  19251. {
  19252. return this._expanded;
  19253. },
  19254.  
  19255. set expanded(x)
  19256. {
  19257. if (x)
  19258. this.expand();
  19259. else
  19260. this.collapse();
  19261. },
  19262.  
  19263. refresh: function()
  19264. {
  19265. if (!this._element || !this.dataGrid)
  19266. return;
  19267.  
  19268. this._element.removeChildren();
  19269. this.createCells();
  19270. },
  19271.  
  19272. createCell: function(columnIdentifier)
  19273. {
  19274. var cell = document.createElement("td");
  19275. cell.className = columnIdentifier + "-column";
  19276.  
  19277. var alignment = this.dataGrid.aligned[columnIdentifier];
  19278. if (alignment)
  19279. cell.addStyleClass(alignment);
  19280.  
  19281. var data = this.data[columnIdentifier];
  19282. var div = document.createElement("div");
  19283. if (data instanceof Node)
  19284. div.appendChild(data);
  19285. else
  19286. div.textContent = data;
  19287. cell.appendChild(div);
  19288.  
  19289. if (columnIdentifier === this.dataGrid.disclosureColumnIdentifier) {
  19290. cell.addStyleClass("disclosure");
  19291. if (this.leftPadding)
  19292. cell.style.setProperty("padding-left", this.leftPadding + "px");
  19293. }
  19294.  
  19295. return cell;
  19296. },
  19297.  
  19298.  
  19299. nodeHeight: function()
  19300. {
  19301. var rowHeight = 16;
  19302. if (!this.revealed)
  19303. return 0;
  19304. if (!this.expanded)
  19305. return rowHeight;
  19306. var result = rowHeight;
  19307. for (var i = 0; i < this.children.length; i++)
  19308. result += this.children[i].nodeHeight();
  19309. return result;
  19310. },
  19311.  
  19312.  
  19313. appendChild: function(child)
  19314. {
  19315. this.insertChild(child, this.children.length);
  19316. },
  19317.  
  19318.  
  19319. insertChild: function(child, index)
  19320. {
  19321. if (!child)
  19322. throw("insertChild: Node can't be undefined or null.");
  19323. if (child.parent === this)
  19324. throw("insertChild: Node is already a child of this node.");
  19325.  
  19326. if (child.parent)
  19327. child.parent.removeChild(child);
  19328.  
  19329. this.children.splice(index, 0, child);
  19330. this.hasChildren = true;
  19331.  
  19332. child.parent = this;
  19333. child.dataGrid = this.dataGrid;
  19334. child._recalculateSiblings(index);
  19335.  
  19336. delete child._depth;
  19337. delete child._revealed;
  19338. delete child._attached;
  19339. child._shouldRefreshChildren = true;
  19340.  
  19341. var current = child.children[0];
  19342. while (current) {
  19343. current.dataGrid = this.dataGrid;
  19344. delete current._depth;
  19345. delete current._revealed;
  19346. delete current._attached;
  19347. current._shouldRefreshChildren = true;
  19348. current = current.traverseNextNode(false, child, true);
  19349. }
  19350.  
  19351. if (this.expanded)
  19352. child._attach();
  19353. if (!this.revealed)
  19354. child.revealed = false;
  19355. },
  19356.  
  19357.  
  19358. removeChild: function(child)
  19359. {
  19360. if (!child)
  19361. throw("removeChild: Node can't be undefined or null.");
  19362. if (child.parent !== this)
  19363. throw("removeChild: Node is not a child of this node.");
  19364.  
  19365. child.deselect();
  19366. child._detach();
  19367.  
  19368. this.children.remove(child, true);
  19369.  
  19370. if (child.previousSibling)
  19371. child.previousSibling.nextSibling = child.nextSibling;
  19372. if (child.nextSibling)
  19373. child.nextSibling.previousSibling = child.previousSibling;
  19374.  
  19375. child.dataGrid = null;
  19376. child.parent = null;
  19377. child.nextSibling = null;
  19378. child.previousSibling = null;
  19379.  
  19380. if (this.children.length <= 0)
  19381. this.hasChildren = false;
  19382. },
  19383.  
  19384. removeChildren: function()
  19385. {
  19386. for (var i = 0; i < this.children.length; ++i) {
  19387. var child = this.children[i];
  19388. child.deselect();
  19389. child._detach();
  19390.  
  19391. child.dataGrid = null;
  19392. child.parent = null;
  19393. child.nextSibling = null;
  19394. child.previousSibling = null;
  19395. }
  19396.  
  19397. this.children = [];
  19398. this.hasChildren = false;
  19399. },
  19400.  
  19401. _recalculateSiblings: function(myIndex)
  19402. {
  19403. if (!this.parent)
  19404. return;
  19405.  
  19406. var previousChild = (myIndex > 0 ? this.parent.children[myIndex - 1] : null);
  19407.  
  19408. if (previousChild) {
  19409. previousChild.nextSibling = this;
  19410. this.previousSibling = previousChild;
  19411. } else
  19412. this.previousSibling = null;
  19413.  
  19414. var nextChild = this.parent.children[myIndex + 1];
  19415.  
  19416. if (nextChild) {
  19417. nextChild.previousSibling = this;
  19418. this.nextSibling = nextChild;
  19419. } else
  19420. this.nextSibling = null;
  19421. },
  19422.  
  19423. collapse: function()
  19424. {
  19425. if (this._isRoot)
  19426. return;
  19427. if (this._element)
  19428. this._element.removeStyleClass("expanded");
  19429.  
  19430. this._expanded = false;
  19431.  
  19432. for (var i = 0; i < this.children.length; ++i)
  19433. this.children[i].revealed = false;
  19434.  
  19435. this.dispatchEventToListeners("collapsed");
  19436. },
  19437.  
  19438. collapseRecursively: function()
  19439. {
  19440. var item = this;
  19441. while (item) {
  19442. if (item.expanded)
  19443. item.collapse();
  19444. item = item.traverseNextNode(false, this, true);
  19445. }
  19446. },
  19447.  
  19448. expand: function()
  19449. {
  19450. if (!this.hasChildren || this.expanded)
  19451. return;
  19452. if (this._isRoot)
  19453. return;
  19454.  
  19455. if (this.revealed && !this._shouldRefreshChildren)
  19456. for (var i = 0; i < this.children.length; ++i)
  19457. this.children[i].revealed = true;
  19458.  
  19459. if (this._shouldRefreshChildren) {
  19460. for (var i = 0; i < this.children.length; ++i)
  19461. this.children[i]._detach();
  19462.  
  19463. this.dispatchEventToListeners("populate");
  19464.  
  19465. if (this._attached) {
  19466. for (var i = 0; i < this.children.length; ++i) {
  19467. var child = this.children[i];
  19468. if (this.revealed)
  19469. child.revealed = true;
  19470. child._attach();
  19471. }
  19472. }
  19473.  
  19474. delete this._shouldRefreshChildren;
  19475. }
  19476.  
  19477. if (this._element)
  19478. this._element.addStyleClass("expanded");
  19479.  
  19480. this._expanded = true;
  19481.  
  19482. this.dispatchEventToListeners("expanded");
  19483. },
  19484.  
  19485. expandRecursively: function()
  19486. {
  19487. var item = this;
  19488. while (item) {
  19489. item.expand();
  19490. item = item.traverseNextNode(false, this);
  19491. }
  19492. },
  19493.  
  19494. reveal: function()
  19495. {
  19496. if (this._isRoot)
  19497. return;
  19498. var currentAncestor = this.parent;
  19499. while (currentAncestor && !currentAncestor._isRoot) {
  19500. if (!currentAncestor.expanded)
  19501. currentAncestor.expand();
  19502. currentAncestor = currentAncestor.parent;
  19503. }
  19504.  
  19505. this.element.scrollIntoViewIfNeeded(false);
  19506.  
  19507. this.dispatchEventToListeners("revealed");
  19508. },
  19509.  
  19510.  
  19511. select: function(supressSelectedEvent)
  19512. {
  19513. if (!this.dataGrid || !this.selectable || this.selected)
  19514. return;
  19515.  
  19516. if (this.dataGrid.selectedNode)
  19517. this.dataGrid.selectedNode.deselect();
  19518.  
  19519. this._selected = true;
  19520. this.dataGrid.selectedNode = this;
  19521.  
  19522. if (this._element)
  19523. this._element.addStyleClass("selected");
  19524.  
  19525. if (!supressSelectedEvent) {
  19526. this.dispatchEventToListeners("selected");
  19527. this.dataGrid.dispatchEventToListeners(WebInspector.DataGrid.Events.SelectedNode);
  19528. }
  19529. },
  19530.  
  19531. revealAndSelect: function()
  19532. {
  19533. if (this._isRoot)
  19534. return;
  19535. this.reveal();
  19536. this.select();
  19537. },
  19538.  
  19539.  
  19540. deselect: function(supressDeselectedEvent)
  19541. {
  19542. if (!this.dataGrid || this.dataGrid.selectedNode !== this || !this.selected)
  19543. return;
  19544.  
  19545. this._selected = false;
  19546. this.dataGrid.selectedNode = null;
  19547.  
  19548. if (this._element)
  19549. this._element.removeStyleClass("selected");
  19550.  
  19551. if (!supressDeselectedEvent) {
  19552. this.dispatchEventToListeners("deselected");
  19553. this.dataGrid.dispatchEventToListeners(WebInspector.DataGrid.Events.DeselectedNode);
  19554. }
  19555. },
  19556.  
  19557. traverseNextNode: function(skipHidden, stayWithin, dontPopulate, info)
  19558. {
  19559. if (!dontPopulate && this.hasChildren)
  19560. this.dispatchEventToListeners("populate");
  19561.  
  19562. if (info)
  19563. info.depthChange = 0;
  19564.  
  19565. var node = (!skipHidden || this.revealed) ? this.children[0] : null;
  19566. if (node && (!skipHidden || this.expanded)) {
  19567. if (info)
  19568. info.depthChange = 1;
  19569. return node;
  19570. }
  19571.  
  19572. if (this === stayWithin)
  19573. return null;
  19574.  
  19575. node = (!skipHidden || this.revealed) ? this.nextSibling : null;
  19576. if (node)
  19577. return node;
  19578.  
  19579. node = this;
  19580. while (node && !node._isRoot && !((!skipHidden || node.revealed) ? node.nextSibling : null) && node.parent !== stayWithin) {
  19581. if (info)
  19582. info.depthChange -= 1;
  19583. node = node.parent;
  19584. }
  19585.  
  19586. if (!node)
  19587. return null;
  19588.  
  19589. return (!skipHidden || node.revealed) ? node.nextSibling : null;
  19590. },
  19591.  
  19592. traversePreviousNode: function(skipHidden, dontPopulate)
  19593. {
  19594. var node = (!skipHidden || this.revealed) ? this.previousSibling : null;
  19595. if (!dontPopulate && node && node.hasChildren)
  19596. node.dispatchEventToListeners("populate");
  19597.  
  19598. while (node && ((!skipHidden || (node.revealed && node.expanded)) ? node.children[node.children.length - 1] : null)) {
  19599. if (!dontPopulate && node.hasChildren)
  19600. node.dispatchEventToListeners("populate");
  19601. node = ((!skipHidden || (node.revealed && node.expanded)) ? node.children[node.children.length - 1] : null);
  19602. }
  19603.  
  19604. if (node)
  19605. return node;
  19606.  
  19607. if (!this.parent || this.parent._isRoot)
  19608. return null;
  19609.  
  19610. return this.parent;
  19611. },
  19612.  
  19613. isEventWithinDisclosureTriangle: function(event)
  19614. {
  19615. if (!this.hasChildren)
  19616. return false;
  19617. var cell = event.target.enclosingNodeOrSelfWithNodeName("td");
  19618. if (!cell.hasStyleClass("disclosure"))
  19619. return false;
  19620.  
  19621. var left = cell.totalOffsetLeft() + this.leftPadding;
  19622. return event.pageX >= left && event.pageX <= left + this.disclosureToggleWidth;
  19623. },
  19624.  
  19625. _attach: function()
  19626. {
  19627. if (!this.dataGrid || this._attached)
  19628. return;
  19629.  
  19630. this._attached = true;
  19631.  
  19632. var nextNode = null;
  19633. var previousNode = this.traversePreviousNode(true, true);
  19634. if (previousNode && previousNode.element.parentNode && previousNode.element.nextSibling)
  19635. nextNode = previousNode.element.nextSibling;
  19636. if (!nextNode)
  19637. nextNode = this.dataGrid.dataTableBody.firstChild;
  19638. this.dataGrid.dataTableBody.insertBefore(this.element, nextNode);
  19639.  
  19640. if (this.expanded)
  19641. for (var i = 0; i < this.children.length; ++i)
  19642. this.children[i]._attach();
  19643. },
  19644.  
  19645. _detach: function()
  19646. {
  19647. if (!this._attached)
  19648. return;
  19649.  
  19650. this._attached = false;
  19651.  
  19652. if (this._element && this._element.parentNode)
  19653. this._element.parentNode.removeChild(this._element);
  19654.  
  19655. for (var i = 0; i < this.children.length; ++i)
  19656. this.children[i]._detach();
  19657.  
  19658. this.wasDetached();
  19659. },
  19660.  
  19661. wasDetached: function()
  19662. {
  19663. },
  19664.  
  19665. savePosition: function()
  19666. {
  19667. if (this._savedPosition)
  19668. return;
  19669.  
  19670. if (!this.parent)
  19671. throw("savePosition: Node must have a parent.");
  19672. this._savedPosition = {
  19673. parent: this.parent,
  19674. index: this.parent.children.indexOf(this)
  19675. };
  19676. },
  19677.  
  19678. restorePosition: function()
  19679. {
  19680. if (!this._savedPosition)
  19681. return;
  19682.  
  19683. if (this.parent !== this._savedPosition.parent)
  19684. this._savedPosition.parent.insertChild(this, this._savedPosition.index);
  19685.  
  19686. delete this._savedPosition;
  19687. },
  19688.  
  19689. __proto__: WebInspector.Object.prototype
  19690. }
  19691.  
  19692.  
  19693. WebInspector.CreationDataGridNode = function(data, hasChildren)
  19694. {
  19695. WebInspector.DataGridNode.call(this, data, hasChildren);
  19696. this.isCreationNode = true;
  19697. }
  19698.  
  19699. WebInspector.CreationDataGridNode.prototype = {
  19700. makeNormal: function()
  19701. {
  19702. delete this.isCreationNode;
  19703. delete this.makeNormal;
  19704. },
  19705.  
  19706. __proto__: WebInspector.DataGridNode.prototype
  19707. }
  19708.  
  19709.  
  19710.  
  19711.  
  19712.  
  19713.  
  19714. WebInspector.ShowMoreDataGridNode = function(callback, startPosition, endPosition, chunkSize)
  19715. {
  19716. WebInspector.DataGridNode.call(this, {summaryRow:true}, false);
  19717. this._callback = callback;
  19718. this._startPosition = startPosition;
  19719. this._endPosition = endPosition;
  19720. this._chunkSize = chunkSize;
  19721.  
  19722. this.showNext = document.createElement("button");
  19723. this.showNext.setAttribute("type", "button");
  19724. this.showNext.addEventListener("click", this._showNextChunk.bind(this), false);
  19725. this.showNext.textContent = WebInspector.UIString("Show %d before", this._chunkSize);
  19726.  
  19727. this.showAll = document.createElement("button");
  19728. this.showAll.setAttribute("type", "button");
  19729. this.showAll.addEventListener("click", this._showAll.bind(this), false);
  19730.  
  19731. this.showLast = document.createElement("button");
  19732. this.showLast.setAttribute("type", "button");
  19733. this.showLast.addEventListener("click", this._showLastChunk.bind(this), false);
  19734. this.showLast.textContent = WebInspector.UIString("Show %d after", this._chunkSize);
  19735.  
  19736. this._updateLabels();
  19737. this.selectable = false;
  19738. }
  19739.  
  19740. WebInspector.ShowMoreDataGridNode.prototype = {
  19741. _showNextChunk: function()
  19742. {
  19743. this._callback(this._startPosition, this._startPosition + this._chunkSize);
  19744. },
  19745.  
  19746. _showAll: function()
  19747. {
  19748. this._callback(this._startPosition, this._endPosition);
  19749. },
  19750.  
  19751. _showLastChunk: function()
  19752. {
  19753. this._callback(this._endPosition - this._chunkSize, this._endPosition);
  19754. },
  19755.  
  19756. _updateLabels: function()
  19757. {
  19758. var totalSize = this._endPosition - this._startPosition;
  19759. if (totalSize > this._chunkSize) {
  19760. this.showNext.removeStyleClass("hidden");
  19761. this.showLast.removeStyleClass("hidden");
  19762. } else {
  19763. this.showNext.addStyleClass("hidden");
  19764. this.showLast.addStyleClass("hidden");
  19765. }
  19766. this.showAll.textContent = WebInspector.UIString("Show all %d", totalSize);
  19767. },
  19768.  
  19769. createCells: function()
  19770. {
  19771. var cell = document.createElement("td");
  19772. if (this.depth)
  19773. cell.style.setProperty("padding-left", (this.depth * this.dataGrid.indentWidth) + "px");
  19774. cell.appendChild(this.showNext);
  19775. cell.appendChild(this.showAll);
  19776. cell.appendChild(this.showLast);
  19777. this._element.appendChild(cell);
  19778.  
  19779. var columns = this.dataGrid.columns;
  19780. var count = 0;
  19781. for (var c in columns)
  19782. ++count;
  19783. while (--count > 0) {
  19784. cell = document.createElement("td");
  19785. this._element.appendChild(cell);
  19786. }
  19787. },
  19788.  
  19789.  
  19790. setStartPosition: function(from)
  19791. {
  19792. this._startPosition = from;
  19793. this._updateLabels();
  19794. },
  19795.  
  19796.  
  19797. setEndPosition: function(to)
  19798. {
  19799. this._endPosition = to;
  19800. this._updateLabels();
  19801. },
  19802.  
  19803.  
  19804. nodeHeight: function()
  19805. {
  19806. return 32;
  19807. },
  19808.  
  19809. dispose: function()
  19810. {
  19811. },
  19812.  
  19813. __proto__: WebInspector.DataGridNode.prototype
  19814. }
  19815.  
  19816.  
  19817.  
  19818.  
  19819.  
  19820.  
  19821.  
  19822. WebInspector.CookiesTable = function(expandable, deleteCallback, refreshCallback)
  19823. {
  19824. WebInspector.View.call(this);
  19825. this.element.className = "fill";
  19826.  
  19827. var columns = { 0: {}, 1: {}, 2: {}, 3: {}, 4: {}, 5: {}, 6: {}, 7: {} };
  19828. columns[0].title = WebInspector.UIString("Name");
  19829. columns[0].sortable = true;
  19830. columns[0].disclosure = expandable;
  19831. columns[0].width = "24%";
  19832. columns[1].title = WebInspector.UIString("Value");
  19833. columns[1].sortable = true;
  19834. columns[1].width = "34%";
  19835. columns[2].title = WebInspector.UIString("Domain");
  19836. columns[2].sortable = true;
  19837. columns[2].width = "7%";
  19838. columns[3].title = WebInspector.UIString("Path");
  19839. columns[3].sortable = true;
  19840. columns[3].width = "7%";
  19841. columns[4].title = WebInspector.UIString("Expires / Max-Age");
  19842. columns[4].sortable = true;
  19843. columns[4].width = "7%";
  19844. columns[5].title = WebInspector.UIString("Size");
  19845. columns[5].aligned = "right";
  19846. columns[5].sortable = true;
  19847. columns[5].width = "7%";
  19848. columns[6].title = WebInspector.UIString("HTTP");
  19849. columns[6].aligned = "centered";
  19850. columns[6].sortable = true;
  19851. columns[6].width = "7%";
  19852. columns[7].title = WebInspector.UIString("Secure");
  19853. columns[7].aligned = "centered";
  19854. columns[7].sortable = true;
  19855. columns[7].width = "7%";
  19856.  
  19857. this._dataGrid = new WebInspector.DataGrid(columns, undefined, deleteCallback ? this._onDeleteFromGrid.bind(this, deleteCallback) : undefined);
  19858. this._dataGrid.addEventListener("sorting changed", this._rebuildTable, this);
  19859. this._dataGrid.refreshCallback = refreshCallback;
  19860.  
  19861. this._dataGrid.show(this.element);
  19862. this._data = [];
  19863. }
  19864.  
  19865. WebInspector.CookiesTable.prototype = {
  19866. updateWidths: function()
  19867. {
  19868. if (this._dataGrid)
  19869. this._dataGrid.updateWidths();
  19870. },
  19871.  
  19872. setCookies: function(cookies)
  19873. {
  19874. this._data = [{cookies: cookies}];
  19875. this._rebuildTable();
  19876. },
  19877.  
  19878.  
  19879. addCookiesFolder: function(folderName, cookies)
  19880. {
  19881. this._data.push({cookies: cookies, folderName: folderName});
  19882. this._rebuildTable();
  19883. },
  19884.  
  19885. get selectedCookie()
  19886. {
  19887. var node = this._dataGrid.selectedNode;
  19888. return node ? node.cookie : null;
  19889. },
  19890.  
  19891. _rebuildTable: function()
  19892. {
  19893. this._dataGrid.rootNode().removeChildren();
  19894. for (var i = 0; i < this._data.length; ++i) {
  19895. var item = this._data[i];
  19896. if (item.folderName) {
  19897. var groupData = [ item.folderName, "", "", "", "", this._totalSize(item.cookies), "", "" ];
  19898. var groupNode = new WebInspector.DataGridNode(groupData);
  19899. groupNode.selectable = true;
  19900. this._dataGrid.rootNode().appendChild(groupNode);
  19901. groupNode.element.addStyleClass("row-group");
  19902. this._populateNode(groupNode, item.cookies);
  19903. groupNode.expand();
  19904. } else
  19905. this._populateNode(this._dataGrid.rootNode(), item.cookies);
  19906. }
  19907. },
  19908.  
  19909.  
  19910. _populateNode: function(parentNode, cookies)
  19911. {
  19912. var selectedCookie = this.selectedCookie;
  19913. parentNode.removeChildren();
  19914. if (!cookies)
  19915. return;
  19916.  
  19917. this._sortCookies(cookies);
  19918. for (var i = 0; i < cookies.length; ++i) {
  19919. var cookieNode = this._createGridNode(cookies[i]);
  19920. parentNode.appendChild(cookieNode);
  19921. if (selectedCookie === cookies[i])
  19922. cookieNode.selected = true;
  19923. }
  19924. },
  19925.  
  19926. _totalSize: function(cookies)
  19927. {
  19928. var totalSize = 0;
  19929. for (var i = 0; cookies && i < cookies.length; ++i)
  19930. totalSize += cookies[i].size();
  19931. return totalSize;
  19932. },
  19933.  
  19934.  
  19935. _sortCookies: function(cookies)
  19936. {
  19937. var sortDirection = this._dataGrid.sortOrder === "ascending" ? 1 : -1;
  19938.  
  19939. function localeCompare(getter, cookie1, cookie2)
  19940. {
  19941. return sortDirection * (getter.apply(cookie1) + "").localeCompare(getter.apply(cookie2) + "")
  19942. }
  19943.  
  19944. function numberCompare(getter, cookie1, cookie2)
  19945. {
  19946. return sortDirection * (getter.apply(cookie1) - getter.apply(cookie2));
  19947. }
  19948.  
  19949. function expiresCompare(cookie1, cookie2)
  19950. {
  19951. if (cookie1.session() !== cookie2.session())
  19952. return sortDirection * (cookie1.session() ? 1 : -1);
  19953.  
  19954. if (cookie1.session())
  19955. return 0;
  19956.  
  19957. if (cookie1.maxAge() && cookie2.maxAge())
  19958. return sortDirection * (cookie1.maxAge() - cookie2.maxAge());
  19959. if (cookie1.expires() && cookie2.expires())
  19960. return sortDirection * (cookie1.expires() - cookie2.expires());
  19961. return sortDirection * (cookie1.expires() ? 1 : -1);
  19962. }
  19963.  
  19964. var comparator;
  19965. switch (parseInt(this._dataGrid.sortColumnIdentifier, 10)) {
  19966. case 0: comparator = localeCompare.bind(null, WebInspector.Cookie.prototype.name); break;
  19967. case 1: comparator = localeCompare.bind(null, WebInspector.Cookie.prototype.value); break;
  19968. case 2: comparator = localeCompare.bind(null, WebInspector.Cookie.prototype.domain); break;
  19969. case 3: comparator = localeCompare.bind(null, WebInspector.Cookie.prototype.path); break;
  19970. case 4: comparator = expiresCompare; break;
  19971. case 5: comparator = numberCompare.bind(null, WebInspector.Cookie.prototype.size); break;
  19972. case 6: comparator = localeCompare.bind(null, WebInspector.Cookie.prototype.httpOnly); break;
  19973. case 7: comparator = localeCompare.bind(null, WebInspector.Cookie.prototype.secure); break;
  19974. default: localeCompare.bind(null, WebInspector.Cookie.prototype.name);
  19975. }
  19976.  
  19977. cookies.sort(comparator);
  19978. },
  19979.  
  19980.  
  19981. _createGridNode: function(cookie)
  19982. {
  19983. var data = {};
  19984. data[0] = cookie.name();
  19985. data[1] = cookie.value();
  19986. data[2] = cookie.domain() || "";
  19987. data[3] = cookie.path() || "";
  19988. if (cookie.type() === WebInspector.Cookie.Type.Request)
  19989. data[4] = "";
  19990. else if (cookie.maxAge())
  19991. data[4] = Number.secondsToString(parseInt(cookie.maxAge(), 10));
  19992. else if (cookie.expires())
  19993. data[4] = new Date(cookie.expires()).toGMTString();
  19994. else
  19995. data[4] = WebInspector.UIString("Session");
  19996. data[5] = cookie.size();
  19997. const checkmark = "\u2713";
  19998. data[6] = (cookie.httpOnly() ? checkmark : "");
  19999. data[7] = (cookie.secure() ? checkmark : "");
  20000.  
  20001. var node = new WebInspector.DataGridNode(data);
  20002. node.cookie = cookie;
  20003. node.selectable = true;
  20004. return node;
  20005. },
  20006.  
  20007. _onDeleteFromGrid: function(deleteCallback, node)
  20008. {
  20009. deleteCallback(node.cookie);
  20010. },
  20011.  
  20012. __proto__: WebInspector.View.prototype
  20013. }
  20014.  
  20015.  
  20016.  
  20017.  
  20018.  
  20019.  
  20020. WebInspector.CookieItemsView = function(treeElement, cookieDomain)
  20021. {
  20022. WebInspector.View.call(this);
  20023.  
  20024. this.element.addStyleClass("storage-view");
  20025.  
  20026. this._deleteButton = new WebInspector.StatusBarButton(WebInspector.UIString("Delete"), "delete-storage-status-bar-item");
  20027. this._deleteButton.visible = false;
  20028. this._deleteButton.addEventListener("click", this._deleteButtonClicked, this);
  20029.  
  20030. this._refreshButton = new WebInspector.StatusBarButton(WebInspector.UIString("Refresh"), "refresh-storage-status-bar-item");
  20031. this._refreshButton.addEventListener("click", this._refreshButtonClicked, this);
  20032.  
  20033. this._treeElement = treeElement;
  20034. this._cookieDomain = cookieDomain;
  20035.  
  20036. this._emptyView = new WebInspector.EmptyView(WebInspector.UIString("This site has no cookies."));
  20037. this._emptyView.show(this.element);
  20038.  
  20039. this.element.addEventListener("contextmenu", this._contextMenu.bind(this), true);
  20040. }
  20041.  
  20042. WebInspector.CookieItemsView.prototype = {
  20043. get statusBarItems()
  20044. {
  20045. return [this._refreshButton.element, this._deleteButton.element];
  20046. },
  20047.  
  20048. wasShown: function()
  20049. {
  20050. this._update();
  20051. },
  20052.  
  20053. willHide: function()
  20054. {
  20055. this._deleteButton.visible = false;
  20056. },
  20057.  
  20058. _update: function()
  20059. {
  20060. WebInspector.Cookies.getCookiesAsync(this._updateWithCookies.bind(this));
  20061. },
  20062.  
  20063.  
  20064. _updateWithCookies: function(allCookies, isAdvanced)
  20065. {
  20066. this._cookies = isAdvanced ? this._filterCookiesForDomain(allCookies) : allCookies;
  20067.  
  20068. if (!this._cookies.length) {
  20069.  
  20070. this._emptyView.show(this.element);
  20071. this._deleteButton.visible = false;
  20072. if (this._cookiesTable)
  20073. this._cookiesTable.detach();
  20074. return;
  20075. }
  20076.  
  20077. if (!this._cookiesTable)
  20078. this._cookiesTable = isAdvanced ? new WebInspector.CookiesTable(false, this._deleteCookie.bind(this), this._update.bind(this)) : new WebInspector.SimpleCookiesTable();
  20079.  
  20080. this._cookiesTable.setCookies(this._cookies);
  20081. this._emptyView.detach();
  20082. this._cookiesTable.show(this.element);
  20083. if (isAdvanced) {
  20084. this._treeElement.subtitle = String.sprintf(WebInspector.UIString("%d cookies (%s)"), this._cookies.length,
  20085. Number.bytesToString(this._totalSize));
  20086. this._deleteButton.visible = true;
  20087. }
  20088. },
  20089.  
  20090.  
  20091. _filterCookiesForDomain: function(allCookies)
  20092. {
  20093. var cookies = [];
  20094. var resourceURLsForDocumentURL = [];
  20095. this._totalSize = 0;
  20096.  
  20097. function populateResourcesForDocuments(resource)
  20098. {
  20099. var url = resource.documentURL.asParsedURL();
  20100. if (url && url.host == this._cookieDomain)
  20101. resourceURLsForDocumentURL.push(resource.url);
  20102. }
  20103. WebInspector.forAllResources(populateResourcesForDocuments.bind(this));
  20104.  
  20105. for (var i = 0; i < allCookies.length; ++i) {
  20106. var pushed = false;
  20107. var size = allCookies[i].size();
  20108. for (var j = 0; j < resourceURLsForDocumentURL.length; ++j) {
  20109. var resourceURL = resourceURLsForDocumentURL[j];
  20110. if (WebInspector.Cookies.cookieMatchesResourceURL(allCookies[i], resourceURL)) {
  20111. this._totalSize += size;
  20112. if (!pushed) {
  20113. pushed = true;
  20114. cookies.push(allCookies[i]);
  20115. }
  20116. }
  20117. }
  20118. }
  20119. return cookies;
  20120. },
  20121.  
  20122.  
  20123. _deleteCookie: function(cookie)
  20124. {
  20125. PageAgent.deleteCookie(cookie.name(), this._cookieDomain);
  20126. this._update();
  20127. },
  20128.  
  20129. _deleteButtonClicked: function()
  20130. {
  20131. if (this._cookiesTable.selectedCookie)
  20132. this._deleteCookie(this._cookiesTable.selectedCookie);
  20133. },
  20134.  
  20135. _refreshButtonClicked: function(event)
  20136. {
  20137. this._update();
  20138. },
  20139.  
  20140. _contextMenu: function(event)
  20141. {
  20142. if (!this._cookies.length) {
  20143. var contextMenu = new WebInspector.ContextMenu(event);
  20144. contextMenu.appendItem(WebInspector.UIString("Refresh"), this._update.bind(this));
  20145. contextMenu.show();
  20146. }
  20147. },
  20148.  
  20149. __proto__: WebInspector.View.prototype
  20150. }
  20151.  
  20152.  
  20153. WebInspector.SimpleCookiesTable = function()
  20154. {
  20155. WebInspector.View.call(this);
  20156.  
  20157. var columns = {};
  20158. columns[0] = {};
  20159. columns[1] = {};
  20160. columns[0].title = WebInspector.UIString("Name");
  20161. columns[1].title = WebInspector.UIString("Value");
  20162.  
  20163. this._dataGrid = new WebInspector.DataGrid(columns);
  20164. this._dataGrid.autoSizeColumns(20, 80);
  20165. this._dataGrid.show(this.element);
  20166. }
  20167.  
  20168. WebInspector.SimpleCookiesTable.prototype = {
  20169.  
  20170. setCookies: function(cookies)
  20171. {
  20172. this._dataGrid.rootNode().removeChildren();
  20173. var addedCookies = {};
  20174. for (var i = 0; i < cookies.length; ++i) {
  20175. if (addedCookies[cookies[i].name()])
  20176. continue;
  20177. addedCookies[cookies[i].name()] = true;
  20178. var data = {};
  20179. data[0] = cookies[i].name();
  20180. data[1] = cookies[i].value();
  20181.  
  20182. var node = new WebInspector.DataGridNode(data, false);
  20183. node.selectable = true;
  20184. this._dataGrid.rootNode().appendChild(node);
  20185. }
  20186. this._dataGrid.rootNode().children[0].selected = true;
  20187. },
  20188.  
  20189. __proto__: WebInspector.View.prototype
  20190. }
  20191.  
  20192.  
  20193.  
  20194.  
  20195.  
  20196.  
  20197. WebInspector.ApplicationCacheModel = function()
  20198. {
  20199. ApplicationCacheAgent.enable();
  20200. InspectorBackend.registerApplicationCacheDispatcher(new WebInspector.ApplicationCacheDispatcher(this));
  20201.  
  20202. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameNavigated, this._frameNavigated, this);
  20203. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameDetached, this._frameDetached, this);
  20204.  
  20205. this._statuses = {};
  20206. this._manifestURLsByFrame = {};
  20207.  
  20208. this._mainFrameNavigated();
  20209.  
  20210. this._onLine = true;
  20211. }
  20212.  
  20213. WebInspector.ApplicationCacheModel.EventTypes = {
  20214. FrameManifestStatusUpdated: "FrameManifestStatusUpdated",
  20215. FrameManifestAdded: "FrameManifestAdded",
  20216. FrameManifestRemoved: "FrameManifestRemoved",
  20217. NetworkStateChanged: "NetworkStateChanged"
  20218. }
  20219.  
  20220. WebInspector.ApplicationCacheModel.prototype = {
  20221. _frameNavigated: function(event)
  20222. {
  20223. var frame =   (event.data);
  20224. if (frame.isMainFrame()) {
  20225. this._mainFrameNavigated();
  20226. return;
  20227. }
  20228.  
  20229. ApplicationCacheAgent.getManifestForFrame(frame.id, this._manifestForFrameLoaded.bind(this, frame.id));
  20230. },
  20231.  
  20232.  
  20233. _frameDetached: function(event)
  20234. {
  20235. var frame =   (event.data);
  20236. this._frameManifestRemoved(frame.id);
  20237. },
  20238.  
  20239. _mainFrameNavigated: function()
  20240. {
  20241. ApplicationCacheAgent.getFramesWithManifests(this._framesWithManifestsLoaded.bind(this));
  20242. },
  20243.  
  20244.  
  20245. _manifestForFrameLoaded: function(frameId, error, manifestURL)
  20246. {
  20247. if (error) {
  20248. console.error(error);
  20249. return;
  20250. }
  20251.  
  20252. if (!manifestURL)
  20253. this._frameManifestRemoved(frameId);
  20254. },
  20255.  
  20256.  
  20257. _framesWithManifestsLoaded: function(error, framesWithManifests)
  20258. {
  20259. if (error) {
  20260. console.error(error);
  20261. return;
  20262. }
  20263.  
  20264. for (var i = 0; i < framesWithManifests.length; ++i)
  20265. this._frameManifestUpdated(framesWithManifests[i].frameId, framesWithManifests[i].manifestURL, framesWithManifests[i].status);
  20266. },
  20267.  
  20268.  
  20269. _frameManifestUpdated: function(frameId, manifestURL, status)
  20270. {
  20271. if (status === applicationCache.UNCACHED) {
  20272. this._frameManifestRemoved(frameId);
  20273. return;
  20274. }
  20275.  
  20276. if (!manifestURL)
  20277. return;
  20278.  
  20279. if (this._manifestURLsByFrame[frameId] && manifestURL !== this._manifestURLsByFrame[frameId])
  20280. this._frameManifestRemoved(frameId);
  20281.  
  20282. var statusChanged = this._statuses[frameId] !== status;
  20283. this._statuses[frameId] = status;
  20284.  
  20285. if (!this._manifestURLsByFrame[frameId]) {
  20286. this._manifestURLsByFrame[frameId] = manifestURL;
  20287. this.dispatchEventToListeners(WebInspector.ApplicationCacheModel.EventTypes.FrameManifestAdded, frameId);
  20288. }
  20289.  
  20290. if (statusChanged)
  20291. this.dispatchEventToListeners(WebInspector.ApplicationCacheModel.EventTypes.FrameManifestStatusUpdated, frameId);
  20292. },
  20293.  
  20294.  
  20295. _frameManifestRemoved: function(frameId)
  20296. {
  20297. if (!this._manifestURLsByFrame[frameId])
  20298. return;
  20299.  
  20300. var manifestURL = this._manifestURLsByFrame[frameId];
  20301. delete this._manifestURLsByFrame[frameId];
  20302. delete this._statuses[frameId];
  20303.  
  20304. this.dispatchEventToListeners(WebInspector.ApplicationCacheModel.EventTypes.FrameManifestRemoved, frameId);
  20305. },
  20306.  
  20307.  
  20308. frameManifestURL: function(frameId)
  20309. {
  20310. return this._manifestURLsByFrame[frameId] || "";
  20311. },
  20312.  
  20313.  
  20314. frameManifestStatus: function(frameId)
  20315. {
  20316. return this._statuses[frameId] || applicationCache.UNCACHED;
  20317. },
  20318.  
  20319.  
  20320. get onLine()
  20321. {
  20322. return this._onLine;
  20323. },
  20324.  
  20325.  
  20326. _statusUpdated: function(frameId, manifestURL, status)
  20327. {
  20328. this._frameManifestUpdated(frameId, manifestURL, status);
  20329. },
  20330.  
  20331.  
  20332. requestApplicationCache: function(frameId, callback)
  20333. {
  20334. function callbackWrapper(error, applicationCache)
  20335. {
  20336. if (error) {
  20337. console.error(error);
  20338. callback(null);
  20339. return;
  20340. }
  20341.  
  20342. callback(applicationCache);
  20343. }
  20344.  
  20345. ApplicationCacheAgent.getApplicationCacheForFrame(frameId, callbackWrapper.bind(this));
  20346. },
  20347.  
  20348.  
  20349. _networkStateUpdated: function(isNowOnline)
  20350. {
  20351. this._onLine = isNowOnline;
  20352. this.dispatchEventToListeners(WebInspector.ApplicationCacheModel.EventTypes.NetworkStateChanged, isNowOnline);
  20353. },
  20354.  
  20355. __proto__: WebInspector.Object.prototype
  20356. }
  20357.  
  20358.  
  20359. WebInspector.ApplicationCacheDispatcher = function(applicationCacheModel)
  20360. {
  20361. this._applicationCacheModel = applicationCacheModel;
  20362. }
  20363.  
  20364. WebInspector.ApplicationCacheDispatcher.prototype = {
  20365.  
  20366. applicationCacheStatusUpdated: function(frameId, manifestURL, status)
  20367. {
  20368. this._applicationCacheModel._statusUpdated(frameId, manifestURL, status);
  20369. },
  20370.  
  20371.  
  20372. networkStateUpdated: function(isNowOnline)
  20373. {
  20374. this._applicationCacheModel._networkStateUpdated(isNowOnline);
  20375. }
  20376. }
  20377.  
  20378.  
  20379.  
  20380.  
  20381.  
  20382.  
  20383. WebInspector.IndexedDBModel = function()
  20384. {
  20385. IndexedDBAgent.enable();
  20386.  
  20387. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameAdded, this._frameNavigated, this);
  20388. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameNavigated, this._frameNavigated, this);
  20389. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameDetached, this._frameDetached, this);
  20390.  
  20391. this._frames = {};
  20392. this._databases = new Map();
  20393. this._frameIdsBySecurityOrigin = {};
  20394. this._databaseNamesBySecurityOrigin = {};
  20395.  
  20396. this.refreshDatabaseNames();
  20397. }
  20398.  
  20399. WebInspector.IndexedDBModel.KeyTypes = {
  20400. NumberType:  "number",
  20401. StringType:  "string",
  20402. DateType:    "date",
  20403. ArrayType:   "array"
  20404. };
  20405.  
  20406. WebInspector.IndexedDBModel.KeyPathTypes = {
  20407. NullType:    "null",
  20408. StringType:  "string",
  20409. ArrayType:   "array"
  20410. };
  20411.  
  20412. WebInspector.IndexedDBModel.keyFromIDBKey = function(idbKey)
  20413. {
  20414. if (typeof(idbKey) === "undefined" || idbKey === null)
  20415. return null;
  20416.  
  20417. var key = {};
  20418. switch (typeof(idbKey)) {
  20419. case "number":
  20420. key.number = idbKey;
  20421. key.type = WebInspector.IndexedDBModel.KeyTypes.NumberType;
  20422. break;
  20423. case "string":
  20424. key.string = idbKey;
  20425. key.type = WebInspector.IndexedDBModel.KeyTypes.StringType;
  20426. break;
  20427. case "object":
  20428. if (idbKey instanceof Date) {
  20429. key.date = idbKey.getTime();
  20430. key.type = WebInspector.IndexedDBModel.KeyTypes.DateType;
  20431. } else if (idbKey instanceof Array) {
  20432. key.array = [];
  20433. for (var i = 0; i < idbKey.length; ++i)
  20434. key.array.push(WebInspector.IndexedDBModel.keyFromIDBKey(idbKey[i]));
  20435. key.type = WebInspector.IndexedDBModel.KeyTypes.ArrayType;
  20436. }
  20437. break;
  20438. default:
  20439. return null;
  20440. }
  20441. return key;
  20442. }
  20443.  
  20444. WebInspector.IndexedDBModel.keyRangeFromIDBKeyRange = function(idbKeyRange)
  20445. {
  20446. var IDBKeyRange = window.IDBKeyRange || window.webkitIDBKeyRange;
  20447. if (typeof(idbKeyRange) === "undefined" || idbKeyRange === null)
  20448. return null;
  20449.  
  20450. var keyRange = {};
  20451. keyRange.lower = WebInspector.IndexedDBModel.keyFromIDBKey(idbKeyRange.lower);
  20452. keyRange.upper = WebInspector.IndexedDBModel.keyFromIDBKey(idbKeyRange.upper);
  20453. keyRange.lowerOpen = idbKeyRange.lowerOpen;
  20454. keyRange.upperOpen = idbKeyRange.upperOpen;
  20455. return keyRange;
  20456. }
  20457.  
  20458.  
  20459. WebInspector.IndexedDBModel.idbKeyPathFromKeyPath = function(keyPath)
  20460. {
  20461. var idbKeyPath;
  20462. switch (keyPath.type) {
  20463. case WebInspector.IndexedDBModel.KeyPathTypes.NullType:
  20464. idbKeyPath = null;
  20465. break;
  20466. case WebInspector.IndexedDBModel.KeyPathTypes.StringType:
  20467. idbKeyPath = keyPath.string;
  20468. break;
  20469. case WebInspector.IndexedDBModel.KeyPathTypes.ArrayType:
  20470. idbKeyPath = keyPath.array;
  20471. break;
  20472. }
  20473. return idbKeyPath;
  20474. }
  20475.  
  20476. WebInspector.IndexedDBModel.keyPathStringFromIDBKeyPath = function(idbKeyPath)
  20477. {
  20478. if (typeof idbKeyPath === "string")
  20479. return "\"" + idbKeyPath + "\"";
  20480. if (idbKeyPath instanceof Array)
  20481. return "[\"" + idbKeyPath.join("\", \"") + "\"]";
  20482. return null;
  20483. }
  20484.  
  20485. WebInspector.IndexedDBModel.EventTypes = {
  20486. DatabaseAdded: "DatabaseAdded",
  20487. DatabaseRemoved: "DatabaseRemoved",
  20488. DatabaseLoaded: "DatabaseLoaded"
  20489. }
  20490.  
  20491. WebInspector.IndexedDBModel.prototype = {
  20492. refreshDatabaseNames: function()
  20493. {
  20494. this._reset();
  20495. if (WebInspector.resourceTreeModel.mainFrame)
  20496. this._framesNavigatedRecursively(WebInspector.resourceTreeModel.mainFrame);
  20497. },
  20498.  
  20499.  
  20500. refreshDatabase: function(databaseId)
  20501. {
  20502. this._loadDatabase(databaseId);
  20503. },
  20504.  
  20505.  
  20506. _framesNavigatedRecursively: function(resourceTreeFrame)
  20507. {
  20508. this._processFrameNavigated(resourceTreeFrame);
  20509. for (var i = 0; i < resourceTreeFrame.childFrames.length; ++i)
  20510. this._framesNavigatedRecursively(resourceTreeFrame.childFrames[i]);
  20511. },
  20512.  
  20513.  
  20514. _frameNavigated: function(event)
  20515. {
  20516. var resourceTreeFrame =   (event.data);
  20517. this._processFrameNavigated(resourceTreeFrame);
  20518. },
  20519.  
  20520.  
  20521. _frameDetached: function(event)
  20522. {
  20523. var resourceTreeFrame =   (event.data);
  20524. this._originRemovedFromFrame(resourceTreeFrame.id);
  20525. },
  20526.  
  20527. _reset: function()
  20528. {
  20529. for (var frameId in this._frames)
  20530. this._originRemovedFromFrame(frameId);
  20531. },
  20532.  
  20533.  
  20534. _processFrameNavigated: function(resourceTreeFrame)
  20535. {
  20536. if (resourceTreeFrame.securityOrigin === "null")
  20537. return;
  20538. if (this._frameIdsBySecurityOrigin[resourceTreeFrame.securityOrigin])
  20539. this._originAddedToFrame(resourceTreeFrame.id, resourceTreeFrame.securityOrigin);
  20540. else
  20541. this._loadDatabaseNamesForFrame(resourceTreeFrame.id);
  20542. },
  20543.  
  20544.  
  20545. _originAddedToFrame: function(frameId, securityOrigin)
  20546. {
  20547. if (!this._frameIdsBySecurityOrigin[securityOrigin]) {
  20548. this._frameIdsBySecurityOrigin[securityOrigin] = [];
  20549. this._frameIdsBySecurityOrigin[securityOrigin].push(frameId);
  20550. this._databaseNamesBySecurityOrigin[securityOrigin] = [];
  20551. }
  20552. this._frames[frameId] = new WebInspector.IndexedDBModel.Frame(frameId, securityOrigin);
  20553. },
  20554.  
  20555.  
  20556. _originRemovedFromFrame: function(frameId)
  20557. {
  20558. var currentSecurityOrigin = this._frames[frameId] ? this._frames[frameId].securityOrigin : null;
  20559. if (!currentSecurityOrigin)
  20560. return;
  20561.  
  20562. delete this._frames[frameId];
  20563.  
  20564. var frameIdsForOrigin = this._frameIdsBySecurityOrigin[currentSecurityOrigin];
  20565. for (var i = 0; i < frameIdsForOrigin; ++i) {
  20566. if (frameIdsForOrigin[i] === frameId) {
  20567. frameIdsForOrigin.splice(i, 1);
  20568. break;
  20569. }
  20570. }
  20571. if (!frameIdsForOrigin.length)
  20572. this._originRemoved(currentSecurityOrigin);
  20573. },
  20574.  
  20575.  
  20576. _originRemoved: function(securityOrigin)
  20577. {
  20578. var frameIdsForOrigin = this._frameIdsBySecurityOrigin[securityOrigin];
  20579. for (var i = 0; i < frameIdsForOrigin; ++i)
  20580. delete this._frames[frameIdsForOrigin[i]];
  20581. delete this._frameIdsBySecurityOrigin[securityOrigin];
  20582. for (var i = 0; i < this._databaseNamesBySecurityOrigin[securityOrigin].length; ++i)
  20583. this._databaseRemoved(securityOrigin, this._databaseNamesBySecurityOrigin[securityOrigin][i]);
  20584. delete this._databaseNamesBySecurityOrigin[securityOrigin];
  20585. },
  20586.  
  20587.  
  20588. _updateOriginDatabaseNames: function(securityOrigin, databaseNames)
  20589. {
  20590. var newDatabaseNames = {};
  20591. for (var i = 0; i < databaseNames.length; ++i)
  20592. newDatabaseNames[databaseNames[i]] = true;
  20593. var oldDatabaseNames = {};
  20594. for (var i = 0; i < this._databaseNamesBySecurityOrigin[securityOrigin].length; ++i)
  20595. oldDatabaseNames[databaseNames[i]] = true;
  20596.  
  20597. this._databaseNamesBySecurityOrigin[securityOrigin] = databaseNames;
  20598.  
  20599. for (var databaseName in oldDatabaseNames) {
  20600. if (!newDatabaseNames[databaseName])
  20601. this._databaseRemoved(securityOrigin, databaseName);
  20602. }
  20603. for (var databaseName in newDatabaseNames) {
  20604. if (!oldDatabaseNames[databaseName])
  20605. this._databaseAdded(securityOrigin, databaseName);
  20606. }
  20607.  
  20608. if (!this._databaseNamesBySecurityOrigin[securityOrigin].length)
  20609. this._originRemoved(securityOrigin);
  20610. },
  20611.  
  20612.  
  20613. _databaseAdded: function(securityOrigin, databaseName)
  20614. {
  20615. var databaseId = new WebInspector.IndexedDBModel.DatabaseId(securityOrigin, databaseName);
  20616. this.dispatchEventToListeners(WebInspector.IndexedDBModel.EventTypes.DatabaseAdded, databaseId);
  20617. },
  20618.  
  20619.  
  20620. _databaseRemoved: function(securityOrigin, databaseName)
  20621. {
  20622. var databaseId = new WebInspector.IndexedDBModel.DatabaseId(securityOrigin, databaseName);
  20623. this.dispatchEventToListeners(WebInspector.IndexedDBModel.EventTypes.DatabaseRemoved, databaseId);
  20624. },
  20625.  
  20626.  
  20627. _loadDatabaseNamesForFrame: function(frameId)
  20628. {
  20629.  
  20630. function callback(error, securityOriginWithDatabaseNames)
  20631. {
  20632. if (error) {
  20633. console.error("IndexedDBAgent error: " + error);
  20634. return;
  20635. }
  20636.  
  20637. var databaseNames = securityOriginWithDatabaseNames.databaseNames;
  20638. var oldSecurityOrigin = this._frames[frameId] ? this._frames[frameId].securityOrigin : null;
  20639. if (!oldSecurityOrigin || oldSecurityOrigin !== securityOriginWithDatabaseNames.securityOrigin) {
  20640. this._originRemovedFromFrame(frameId);
  20641. this._originAddedToFrame(frameId, securityOriginWithDatabaseNames.securityOrigin);
  20642. }
  20643. this._updateOriginDatabaseNames(securityOriginWithDatabaseNames.securityOrigin, securityOriginWithDatabaseNames.databaseNames);
  20644. }
  20645.  
  20646. IndexedDBAgent.requestDatabaseNamesForFrame(frameId, callback.bind(this));
  20647. },
  20648.  
  20649.  
  20650. _assertFrameId: function(databaseId)
  20651. {
  20652. var frameIds = this._frameIdsBySecurityOrigin[databaseId.securityOrigin];
  20653. if (!frameIds || !frameIds.length)
  20654. return null;
  20655.  
  20656. return frameIds[0];
  20657. },
  20658.  
  20659.  
  20660. _loadDatabase: function(databaseId)
  20661. {
  20662. var frameId = this._assertFrameId(databaseId);
  20663. if (!frameId)
  20664. return;
  20665.  
  20666.  
  20667. function callback(error, databaseWithObjectStores)
  20668. {
  20669. if (error) {
  20670. console.error("IndexedDBAgent error: " + error);
  20671. return;
  20672. }
  20673.  
  20674. if (!this._frames[frameId])
  20675. return;
  20676.  
  20677. var databaseModel = new WebInspector.IndexedDBModel.Database(databaseId, databaseWithObjectStores.version, databaseWithObjectStores.intVersion);
  20678. this._databases.put(databaseId, databaseModel); 
  20679. for (var i = 0; i < databaseWithObjectStores.objectStores.length; ++i) {
  20680. var objectStore = databaseWithObjectStores.objectStores[i];
  20681. var objectStoreIDBKeyPath = WebInspector.IndexedDBModel.idbKeyPathFromKeyPath(objectStore.keyPath);
  20682. var objectStoreModel = new WebInspector.IndexedDBModel.ObjectStore(objectStore.name, objectStoreIDBKeyPath, objectStore.autoIncrement);
  20683. for (var j = 0; j < objectStore.indexes.length; ++j) {
  20684. var index = objectStore.indexes[j];
  20685. var indexIDBKeyPath = WebInspector.IndexedDBModel.idbKeyPathFromKeyPath(index.keyPath);
  20686. var indexModel = new WebInspector.IndexedDBModel.Index(index.name, indexIDBKeyPath, index.unique, index.multiEntry);
  20687. objectStoreModel.indexes[indexModel.name] = indexModel;
  20688. }
  20689. databaseModel.objectStores[objectStoreModel.name] = objectStoreModel;
  20690. }
  20691.  
  20692. this.dispatchEventToListeners(WebInspector.IndexedDBModel.EventTypes.DatabaseLoaded, databaseModel);
  20693. }
  20694.  
  20695. IndexedDBAgent.requestDatabase(frameId, databaseId.name, callback.bind(this));
  20696. },
  20697.  
  20698.  
  20699. loadObjectStoreData: function(databaseId, objectStoreName, idbKeyRange, skipCount, pageSize, callback)
  20700. {
  20701. this._requestData(databaseId, databaseId.name, objectStoreName, "", idbKeyRange, skipCount, pageSize, callback);
  20702. },
  20703.  
  20704.  
  20705. loadIndexData: function(databaseId, objectStoreName, indexName, idbKeyRange, skipCount, pageSize, callback)
  20706. {
  20707. this._requestData(databaseId, databaseId.name, objectStoreName, indexName, idbKeyRange, skipCount, pageSize, callback);
  20708. },
  20709.  
  20710.  
  20711. _requestData: function(databaseId, databaseName, objectStoreName, indexName, idbKeyRange, skipCount, pageSize, callback)
  20712. {
  20713. var frameId = this._assertFrameId(databaseId);
  20714. if (!frameId)
  20715. return;
  20716.  
  20717.  
  20718. function innerCallback(error, dataEntries, hasMore)
  20719. {
  20720. if (error) {
  20721. console.error("IndexedDBAgent error: " + error);
  20722. return;
  20723. }
  20724.  
  20725. if (!this._frames[frameId])
  20726. return;
  20727.  
  20728. var entries = [];
  20729. for (var i = 0; i < dataEntries.length; ++i) {
  20730. var key = WebInspector.RemoteObject.fromPayload(dataEntries[i].key);
  20731. var primaryKey = WebInspector.RemoteObject.fromPayload(dataEntries[i].primaryKey);
  20732. var value = WebInspector.RemoteObject.fromPayload(dataEntries[i].value);
  20733. entries.push(new WebInspector.IndexedDBModel.Entry(key, primaryKey, value));
  20734. }
  20735. callback(entries, hasMore);
  20736. }
  20737.  
  20738. var keyRange = WebInspector.IndexedDBModel.keyRangeFromIDBKeyRange(idbKeyRange);
  20739. IndexedDBAgent.requestData(frameId, databaseName, objectStoreName, indexName, skipCount, pageSize, keyRange ? keyRange : undefined, innerCallback.bind(this));
  20740. },
  20741.  
  20742. __proto__: WebInspector.Object.prototype
  20743. }
  20744.  
  20745.  
  20746. WebInspector.IndexedDBModel.Entry = function(key, primaryKey, value)
  20747. {
  20748. this.key = key;
  20749. this.primaryKey = primaryKey;
  20750. this.value = value;
  20751. }
  20752.  
  20753.  
  20754. WebInspector.IndexedDBModel.Frame = function(frameId, securityOrigin)
  20755. {
  20756. this.frameId = frameId;
  20757. this.securityOrigin = securityOrigin;
  20758. this.databaseNames = {};
  20759. }
  20760.  
  20761.  
  20762. WebInspector.IndexedDBModel.DatabaseId = function(securityOrigin, name)
  20763. {
  20764. this.securityOrigin = securityOrigin;
  20765. this.name = name;
  20766. }
  20767.  
  20768. WebInspector.IndexedDBModel.DatabaseId.prototype = {
  20769.  
  20770. equals: function(databaseId)
  20771. {
  20772. return this.name === databaseId.name && this.securityOrigin === databaseId.securityOrigin;
  20773. },
  20774. }
  20775.  
  20776. WebInspector.IndexedDBModel.Database = function(databaseId, version, intVersion)
  20777. {
  20778. this.databaseId = databaseId;
  20779. this.version = version;
  20780. this.intVersion = intVersion;
  20781. this.objectStores = {};
  20782. }
  20783.  
  20784.  
  20785. WebInspector.IndexedDBModel.ObjectStore = function(name, keyPath, autoIncrement)
  20786. {
  20787. this.name = name;
  20788. this.keyPath = keyPath;
  20789. this.autoIncrement = autoIncrement;
  20790. this.indexes = {};
  20791. }
  20792.  
  20793. WebInspector.IndexedDBModel.ObjectStore.prototype = {
  20794.  
  20795. get keyPathString()
  20796. {
  20797. return WebInspector.IndexedDBModel.keyPathStringFromIDBKeyPath(this.keyPath);
  20798. }
  20799. }
  20800.  
  20801.  
  20802. WebInspector.IndexedDBModel.Index = function(name, keyPath, unique, multiEntry)
  20803. {
  20804. this.name = name;
  20805. this.keyPath = keyPath;
  20806. this.unique = unique;
  20807. this.multiEntry = multiEntry;
  20808. }
  20809.  
  20810. WebInspector.IndexedDBModel.Index.prototype = {
  20811.  
  20812. get keyPathString()
  20813. {
  20814. return WebInspector.IndexedDBModel.keyPathStringFromIDBKeyPath(this.keyPath);
  20815. }
  20816. }
  20817.  
  20818.  
  20819.  
  20820.  
  20821.  
  20822.  
  20823. WebInspector.Spectrum = function()
  20824. {
  20825. WebInspector.View.call(this);
  20826. this.registerRequiredCSS("spectrum.css");
  20827.  
  20828. this.element.className = "spectrum-container";
  20829. this.element.tabIndex = 0;
  20830.  
  20831. var topElement = this.element.createChild("div", "spectrum-top");
  20832. topElement.createChild("div", "spectrum-fill");
  20833.  
  20834. var topInnerElement = topElement.createChild("div", "spectrum-top-inner fill");
  20835. this._draggerElement = topInnerElement.createChild("div", "spectrum-color");
  20836. this._dragHelperElement = this._draggerElement.createChild("div", "spectrum-sat fill").createChild("div", "spectrum-val fill").createChild("div", "spectrum-dragger");
  20837.  
  20838. this._sliderElement = topInnerElement.createChild("div", "spectrum-hue");
  20839. this.slideHelper = this._sliderElement.createChild("div", "spectrum-slider");
  20840.  
  20841. var rangeContainer = this.element.createChild("div", "spectrum-range-container");
  20842. var alphaLabel = rangeContainer.createChild("label");
  20843. alphaLabel.textContent = WebInspector.UIString("\u03B1:");
  20844.  
  20845. this._alphaElement = rangeContainer.createChild("input", "spectrum-range");
  20846. this._alphaElement.setAttribute("type", "range");
  20847. this._alphaElement.setAttribute("min", "0");
  20848. this._alphaElement.setAttribute("max", "100");
  20849. this._alphaElement.addEventListener("change", alphaDrag.bind(this), false);
  20850.  
  20851. var swatchElement = document.createElement("span");
  20852. swatchElement.className = "swatch";
  20853. this._swatchInnerElement = swatchElement.createChild("span", "swatch-inner");
  20854.  
  20855. var displayContainer = this.element.createChild("div");
  20856. displayContainer.appendChild(swatchElement);
  20857. this._displayElement = displayContainer.createChild("span", "source-code spectrum-display-value");
  20858.  
  20859. WebInspector.Spectrum.draggable(this._sliderElement, hueDrag.bind(this));
  20860. WebInspector.Spectrum.draggable(this._draggerElement, colorDrag.bind(this), colorDragStart.bind(this));
  20861.  
  20862. function hueDrag(element, dragX, dragY)
  20863. {
  20864. this.hsv[0] = (dragY / this.slideHeight);
  20865.  
  20866. this._onchange();
  20867. }
  20868.  
  20869. var initialHelperOffset;
  20870.  
  20871. function colorDragStart(element, dragX, dragY)
  20872. {
  20873. initialHelperOffset = { x: this._dragHelperElement.offsetLeft, y: this._dragHelperElement.offsetTop };
  20874. }
  20875.  
  20876. function colorDrag(element, dragX, dragY, event)
  20877. {
  20878. if (event.shiftKey) {
  20879. if (Math.abs(dragX - initialHelperOffset.x) >= Math.abs(dragY - initialHelperOffset.y))
  20880. dragY = initialHelperOffset.y;
  20881. else
  20882. dragX = initialHelperOffset.x;
  20883. }
  20884.  
  20885. this.hsv[1] = dragX / this.dragWidth;
  20886. this.hsv[2] = (this.dragHeight - dragY) / this.dragHeight;
  20887.  
  20888. this._onchange();
  20889. }
  20890.  
  20891. function alphaDrag()
  20892. {
  20893. this.hsv[3] = this._alphaElement.value / 100;
  20894.  
  20895. this._onchange();
  20896. }
  20897. };
  20898.  
  20899. WebInspector.Spectrum.Events = {
  20900. ColorChanged: "ColorChanged"
  20901. };
  20902.  
  20903. WebInspector.Spectrum.hsvaToRGBA = function(h, s, v, a)
  20904. {
  20905. var r, g, b;
  20906.  
  20907. var i = Math.floor(h * 6);
  20908. var f = h * 6 - i;
  20909. var p = v * (1 - s);
  20910. var q = v * (1 - f * s);
  20911. var t = v * (1 - (1 - f) * s);
  20912.  
  20913. switch(i % 6) {
  20914. case 0:
  20915. r = v, g = t, b = p;
  20916. break;
  20917. case 1:
  20918. r = q, g = v, b = p;
  20919. break;
  20920. case 2:
  20921. r = p, g = v, b = t;
  20922. break;
  20923. case 3:
  20924. r = p, g = q, b = v;
  20925. break;
  20926. case 4:
  20927. r = t, g = p, b = v;
  20928. break;
  20929. case 5:
  20930. r = v, g = p, b = q;
  20931. break;
  20932. }
  20933.  
  20934. return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a];
  20935. };
  20936.  
  20937. WebInspector.Spectrum.rgbaToHSVA = function(r, g, b, a)
  20938. {
  20939. r = r / 255;
  20940. g = g / 255;
  20941. b = b / 255;
  20942.  
  20943. var max = Math.max(r, g, b);
  20944. var min = Math.min(r, g, b);
  20945. var h;
  20946. var s;
  20947. var v = max;
  20948.  
  20949. var d = max - min;
  20950. s = max ? d / max : 0;
  20951.  
  20952. if(max === min) {
  20953.  
  20954. h = 0;
  20955. } else {
  20956. switch(max) {
  20957. case r:
  20958. h = (g - b) / d + (g < b ? 6 : 0);
  20959. break;
  20960. case g:
  20961. h = (b - r) / d + 2;
  20962. break;
  20963. case b:
  20964. h = (r - g) / d + 4;
  20965. break;
  20966. }
  20967. h /= 6;
  20968. }
  20969. return [h, s, v, a];
  20970. };
  20971.  
  20972.  
  20973.  
  20974. WebInspector.Spectrum.draggable = function(element, onmove, onstart, onstop) {
  20975.  
  20976. var doc = document;
  20977. var dragging;
  20978. var offset;
  20979. var scrollOffset;
  20980. var maxHeight;
  20981. var maxWidth;
  20982.  
  20983. function consume(e)
  20984. {
  20985. e.consume(true);
  20986. }
  20987.  
  20988. function move(e)
  20989. {
  20990. if (dragging) {
  20991. var dragX = Math.max(0, Math.min(e.pageX - offset.left + scrollOffset.left, maxWidth));
  20992. var dragY = Math.max(0, Math.min(e.pageY - offset.top + scrollOffset.top, maxHeight));
  20993.  
  20994. if (onmove)
  20995. onmove(element, dragX, dragY, e);
  20996. }
  20997. }
  20998.  
  20999. function start(e)
  21000. {
  21001. var rightClick = e.which ? (e.which === 3) : (e.button === 2);
  21002.  
  21003. if (!rightClick && !dragging) {
  21004.  
  21005. if (onstart)
  21006. onstart(element, e)
  21007.  
  21008. dragging = true;
  21009. maxHeight = element.clientHeight;
  21010. maxWidth = element.clientWidth;
  21011.  
  21012. scrollOffset = element.scrollOffset();
  21013. offset = element.totalOffset();
  21014.  
  21015. doc.addEventListener("selectstart", consume, false);
  21016. doc.addEventListener("dragstart", consume, false);
  21017. doc.addEventListener("mousemove", move, false);
  21018. doc.addEventListener("mouseup", stop, false);
  21019.  
  21020. move(e);
  21021. consume(e);
  21022. }
  21023. }
  21024.  
  21025. function stop(e)
  21026. {
  21027. if (dragging) {
  21028. doc.removeEventListener("selectstart", consume, false);
  21029. doc.removeEventListener("dragstart", consume, false);
  21030. doc.removeEventListener("mousemove", move, false);
  21031. doc.removeEventListener("mouseup", stop, false);
  21032.  
  21033. if (onstop)
  21034. onstop(element, e);
  21035. }
  21036.  
  21037. dragging = false;
  21038. }
  21039.  
  21040. element.addEventListener("mousedown", start, false);
  21041. };
  21042.  
  21043. WebInspector.Spectrum.prototype = {
  21044.  
  21045. set color(color)
  21046. {
  21047. var rgba = (color.rgba || color.rgb).slice(0);
  21048.  
  21049. if (rgba.length === 3)
  21050. rgba[3] = 1;
  21051.  
  21052. this.hsv = WebInspector.Spectrum.rgbaToHSVA(rgba[0], rgba[1], rgba[2], rgba[3]);
  21053. },
  21054.  
  21055. get color()
  21056. {
  21057. var rgba = WebInspector.Spectrum.hsvaToRGBA(this.hsv[0], this.hsv[1], this.hsv[2], this.hsv[3]);
  21058. var color;
  21059.  
  21060. if (rgba[3] === 1)
  21061. color = WebInspector.Color.fromRGB(rgba[0], rgba[1], rgba[2]);
  21062. else
  21063. color = WebInspector.Color.fromRGBA(rgba[0], rgba[1], rgba[2], rgba[3]);
  21064.  
  21065. var colorValue = color.toString(this.outputColorFormat);
  21066. if (!colorValue)
  21067. colorValue = color.toString(); 
  21068. return new WebInspector.Color(colorValue);
  21069. },
  21070.  
  21071. get outputColorFormat()
  21072. {
  21073. var cf = WebInspector.Color.Format;
  21074. var format = this._originalFormat;
  21075.  
  21076. if (this.hsv[3] === 1) {
  21077.  
  21078. if (format === cf.RGBA)
  21079. format = cf.RGB;
  21080. else if (format === cf.HSLA)
  21081. format = cf.HSL;
  21082. } else {
  21083.  
  21084. if (format === cf.HSL || format === cf.HSLA)
  21085. format = cf.HSLA;
  21086. else
  21087. format = cf.RGBA;
  21088. }
  21089.  
  21090. return format;
  21091. },
  21092.  
  21093. get colorHueOnly()
  21094. {
  21095. var rgba = WebInspector.Spectrum.hsvaToRGBA(this.hsv[0], 1, 1, 1);
  21096. return WebInspector.Color.fromRGBA(rgba[0], rgba[1], rgba[2], rgba[3]);
  21097. },
  21098.  
  21099. set displayText(text)
  21100. {
  21101. this._displayElement.textContent = text;
  21102. },
  21103.  
  21104. _onchange: function()
  21105. {
  21106. this._updateUI();
  21107. this.dispatchEventToListeners(WebInspector.Spectrum.Events.ColorChanged, this.color);
  21108. },
  21109.  
  21110. _updateHelperLocations: function()
  21111. {
  21112. var h = this.hsv[0];
  21113. var s = this.hsv[1];
  21114. var v = this.hsv[2];
  21115.  
  21116.  
  21117. var dragX = s * this.dragWidth;
  21118. var dragY = this.dragHeight - (v * this.dragHeight);
  21119.  
  21120. dragX = Math.max(-this._dragHelperElementHeight,
  21121. Math.min(this.dragWidth - this._dragHelperElementHeight, dragX - this._dragHelperElementHeight));
  21122. dragY = Math.max(-this._dragHelperElementHeight,
  21123. Math.min(this.dragHeight - this._dragHelperElementHeight, dragY - this._dragHelperElementHeight));
  21124.  
  21125. this._dragHelperElement.positionAt(dragX, dragY);
  21126.  
  21127.  
  21128. var slideY = (h * this.slideHeight) - this.slideHelperHeight;
  21129. this.slideHelper.style.top = slideY + "px";
  21130.  
  21131. this._alphaElement.value = this.hsv[3] * 100;
  21132. },
  21133.  
  21134. _updateUI: function()
  21135. {
  21136. this._updateHelperLocations();
  21137.  
  21138. var rgb = (this.color.rgba || this.color.rgb).slice(0);
  21139.  
  21140. if (rgb.length === 3)
  21141. rgb[3] = 1;
  21142.  
  21143. var rgbHueOnly = this.colorHueOnly.rgb;
  21144.  
  21145. var flatColor = "rgb(" + rgbHueOnly[0] + ", " + rgbHueOnly[1] + ", " + rgbHueOnly[2] + ")";
  21146. var fullColor = "rgba(" + rgb[0] + ", " + rgb[1] + ", " + rgb[2] + ", " + rgb[3] + ")";
  21147.  
  21148. this._draggerElement.style.backgroundColor = flatColor;
  21149. this._swatchInnerElement.style.backgroundColor = fullColor;
  21150.  
  21151. this._alphaElement.value = this.hsv[3] * 100;
  21152. },
  21153.  
  21154. wasShown: function()
  21155. {
  21156. this.slideHeight = this._sliderElement.offsetHeight;
  21157. this.dragWidth = this._draggerElement.offsetWidth;
  21158. this.dragHeight = this._draggerElement.offsetHeight;
  21159. this._dragHelperElementHeight = this._dragHelperElement.offsetHeight / 2;
  21160. this.slideHelperHeight = this.slideHelper.offsetHeight / 2;
  21161. this._updateUI();
  21162. },
  21163.  
  21164. __proto__: WebInspector.View.prototype
  21165. }
  21166.  
  21167.  
  21168. WebInspector.SpectrumPopupHelper = function()
  21169. {
  21170. this._spectrum = new WebInspector.Spectrum();
  21171. this._spectrum.element.addEventListener("keydown", this._onKeyDown.bind(this), false);
  21172.  
  21173. this._popover = new WebInspector.Popover();
  21174. this._popover.setCanShrink(false);
  21175. this._popover.element.addEventListener("mousedown", consumeEvent, false);
  21176.  
  21177. this._hideProxy = this.hide.bind(this, true);
  21178. }
  21179.  
  21180. WebInspector.SpectrumPopupHelper.Events = {
  21181. Hidden: "Hidden"
  21182. };
  21183.  
  21184. WebInspector.SpectrumPopupHelper.prototype = {
  21185.  
  21186. spectrum: function()
  21187. {
  21188. return this._spectrum;
  21189. },
  21190.  
  21191. toggle: function(element, color, format)
  21192. {
  21193. if (this._popover.isShowing())
  21194. this.hide(true);
  21195. else
  21196. this.show(element, color, format);
  21197.  
  21198. return this._popover.isShowing();
  21199. },
  21200.  
  21201. show: function(element, color, format)
  21202. {
  21203. if (this._popover.isShowing()) {
  21204. if (this._anchorElement === element)
  21205. return false;
  21206.  
  21207.  
  21208. this.hide(true);
  21209. }
  21210.  
  21211. this._anchorElement = element;
  21212.  
  21213. this._spectrum.color = color;
  21214. this._spectrum._originalFormat = format || color.format;
  21215. this.reposition(element);
  21216.  
  21217. document.addEventListener("mousedown", this._hideProxy, false);
  21218. window.addEventListener("blur", this._hideProxy, false);
  21219. return true;
  21220. },
  21221.  
  21222. reposition: function(element)
  21223. {
  21224. if (!this._previousFocusElement)
  21225. this._previousFocusElement = WebInspector.currentFocusElement();
  21226. this._popover.showView(this._spectrum, element);
  21227. WebInspector.setCurrentFocusElement(this._spectrum.element);
  21228. },
  21229.  
  21230.  
  21231. hide: function(commitEdit)
  21232. {
  21233. if (!this._popover.isShowing())
  21234. return;
  21235. this._popover.hide();
  21236.  
  21237. document.removeEventListener("mousedown", this._hideProxy, false);
  21238. window.removeEventListener("blur", this._hideProxy, false);
  21239.  
  21240. this.dispatchEventToListeners(WebInspector.SpectrumPopupHelper.Events.Hidden, !!commitEdit);
  21241.  
  21242. WebInspector.setCurrentFocusElement(this._previousFocusElement);
  21243. delete this._previousFocusElement;
  21244.  
  21245. delete this._anchorElement;
  21246. },
  21247.  
  21248. _onKeyDown: function(event)
  21249. {
  21250. if (event.keyIdentifier === "Enter") {
  21251. this.hide(true);
  21252. event.consume(true);
  21253. return;
  21254. }
  21255. if (event.keyIdentifier === "U+001B") { 
  21256. this.hide(false);
  21257. event.consume(true);
  21258. }
  21259. },
  21260.  
  21261. __proto__: WebInspector.Object.prototype
  21262. }
  21263.  
  21264.  
  21265. WebInspector.ColorSwatch = function()
  21266. {
  21267. this.element = document.createElement("span");
  21268. this._swatchInnerElement = this.element.createChild("span", "swatch-inner");
  21269. this.element.title = WebInspector.UIString("Click to open a colorpicker. Shift-click to change color format");
  21270. this.element.className = "swatch";
  21271. this.element.addEventListener("mousedown", consumeEvent, false);
  21272. this.element.addEventListener("dblclick", consumeEvent, false);
  21273. }
  21274.  
  21275. WebInspector.ColorSwatch.prototype = {
  21276.  
  21277. setColorString: function(colorString)
  21278. {
  21279. this._swatchInnerElement.style.backgroundColor = colorString;
  21280. }
  21281. }
  21282.  
  21283.  
  21284.  
  21285.  
  21286.  
  21287.  
  21288. WebInspector.SidebarPane = function(title)
  21289. {
  21290. this.element = document.createElement("div");
  21291. this.element.className = "pane";
  21292.  
  21293. this.titleElement = document.createElement("div");
  21294. this.titleElement.className = "title";
  21295. this.titleElement.tabIndex = 0;
  21296. this.titleElement.addEventListener("click", this.toggleExpanded.bind(this), false);
  21297. this.titleElement.addEventListener("keydown", this._onTitleKeyDown.bind(this), false);
  21298.  
  21299. this.bodyElement = document.createElement("div");
  21300. this.bodyElement.className = "body";
  21301.  
  21302. this.element.appendChild(this.titleElement);
  21303. this.element.appendChild(this.bodyElement);
  21304.  
  21305. this.title = title;
  21306. this.growbarVisible = false;
  21307. this.expanded = false;
  21308. }
  21309.  
  21310. WebInspector.SidebarPane.prototype = {
  21311. get title()
  21312. {
  21313. return this._title;
  21314. },
  21315.  
  21316. set title(x)
  21317. {
  21318. if (this._title === x)
  21319. return;
  21320. this._title = x;
  21321. this.titleElement.textContent = x;
  21322. },
  21323.  
  21324. get growbarVisible()
  21325. {
  21326. return this._growbarVisible;
  21327. },
  21328.  
  21329. set growbarVisible(x)
  21330. {
  21331. if (this._growbarVisible === x)
  21332. return;
  21333.  
  21334. this._growbarVisible = x;
  21335.  
  21336. if (x && !this._growbarElement) {
  21337. this._growbarElement = document.createElement("div");
  21338. this._growbarElement.className = "growbar";
  21339. this.element.appendChild(this._growbarElement);
  21340. } else if (!x && this._growbarElement) {
  21341. if (this._growbarElement.parentNode)
  21342. this._growbarElement.parentNode(this._growbarElement);
  21343. delete this._growbarElement;
  21344. }
  21345. },
  21346.  
  21347. get expanded()
  21348. {
  21349. return this._expanded;
  21350. },
  21351.  
  21352. set expanded(x)
  21353. {
  21354. if (x)
  21355. this.expand();
  21356. else
  21357. this.collapse();
  21358. },
  21359.  
  21360. expand: function()
  21361. {
  21362. if (this._expanded)
  21363. return;
  21364. this._expanded = true;
  21365. this.element.addStyleClass("expanded");
  21366. this.onexpand();
  21367. },
  21368.  
  21369. onexpand: function()
  21370. {
  21371. },
  21372.  
  21373. collapse: function()
  21374. {
  21375. if (!this._expanded)
  21376. return;
  21377. this._expanded = false;
  21378. this.element.removeStyleClass("expanded");
  21379. },
  21380.  
  21381. toggleExpanded: function()
  21382. {
  21383. this.expanded = !this.expanded;
  21384. },
  21385.  
  21386. _onTitleKeyDown: function(event)
  21387. {
  21388. if (isEnterKey(event) || event.keyCode === WebInspector.KeyboardShortcut.Keys.Space.code)
  21389. this.toggleExpanded();
  21390. },
  21391.  
  21392. __proto__: WebInspector.Object.prototype
  21393. }
  21394.  
  21395.  
  21396.  
  21397.  
  21398.  
  21399.  
  21400. WebInspector.ElementsTreeOutline = function(omitRootDOMNode, selectEnabled, showInElementsPanelEnabled, contextMenuCallback, setPseudoClassCallback)
  21401. {
  21402. this.element = document.createElement("ol");
  21403. this.element.addEventListener("mousedown", this._onmousedown.bind(this), false);
  21404. this.element.addEventListener("mousemove", this._onmousemove.bind(this), false);
  21405. this.element.addEventListener("mouseout", this._onmouseout.bind(this), false);
  21406. this.element.addEventListener("dragstart", this._ondragstart.bind(this), false);
  21407. this.element.addEventListener("dragover", this._ondragover.bind(this), false);
  21408. this.element.addEventListener("dragleave", this._ondragleave.bind(this), false);
  21409. this.element.addEventListener("drop", this._ondrop.bind(this), false);
  21410. this.element.addEventListener("dragend", this._ondragend.bind(this), false);
  21411. this.element.addEventListener("keydown", this._onkeydown.bind(this), false);
  21412.  
  21413. TreeOutline.call(this, this.element);
  21414.  
  21415. this._includeRootDOMNode = !omitRootDOMNode;
  21416. this._selectEnabled = selectEnabled;
  21417. this._showInElementsPanelEnabled = showInElementsPanelEnabled;
  21418. this._rootDOMNode = null;
  21419. this._selectDOMNode = null;
  21420. this._eventSupport = new WebInspector.Object();
  21421.  
  21422. this._visible = false;
  21423.  
  21424. this.element.addEventListener("contextmenu", this._contextMenuEventFired.bind(this), true);
  21425. this._contextMenuCallback = contextMenuCallback;
  21426. this._setPseudoClassCallback = setPseudoClassCallback;
  21427. this._createNodeDecorators();
  21428. }
  21429.  
  21430. WebInspector.ElementsTreeOutline.Events = {
  21431. SelectedNodeChanged: "SelectedNodeChanged"
  21432. }
  21433.  
  21434. WebInspector.ElementsTreeOutline.MappedCharToEntity = {
  21435. "\u00a0": "nbsp",
  21436. "\u2002": "ensp",
  21437. "\u2003": "emsp",
  21438. "\u2009": "thinsp",
  21439. "\u200b": "#8203", 
  21440. "\u200c": "zwnj",
  21441. "\u200d": "zwj",
  21442. "\u200e": "lrm",
  21443. "\u200f": "rlm",
  21444. "\u202a": "#8234", 
  21445. "\u202b": "#8235", 
  21446. "\u202c": "#8236", 
  21447. "\u202d": "#8237", 
  21448. "\u202e": "#8238" 
  21449. }
  21450.  
  21451. WebInspector.ElementsTreeOutline.prototype = {
  21452. _createNodeDecorators: function()
  21453. {
  21454. this._nodeDecorators = [];
  21455. this._nodeDecorators.push(new WebInspector.ElementsTreeOutline.PseudoStateDecorator());
  21456. },
  21457.  
  21458. wireToDomAgent: function()
  21459. {
  21460. this._elementsTreeUpdater = new WebInspector.ElementsTreeUpdater(this);
  21461. },
  21462.  
  21463. setVisible: function(visible)
  21464. {
  21465. this._visible = visible;
  21466. if (!this._visible)
  21467. return;
  21468.  
  21469. this._updateModifiedNodes();
  21470. if (this._selectedDOMNode)
  21471. this._revealAndSelectNode(this._selectedDOMNode, false);
  21472. },
  21473.  
  21474. addEventListener: function(eventType, listener, thisObject)
  21475. {
  21476. this._eventSupport.addEventListener(eventType, listener, thisObject);
  21477. },
  21478.  
  21479. removeEventListener: function(eventType, listener, thisObject)
  21480. {
  21481. this._eventSupport.removeEventListener(eventType, listener, thisObject);
  21482. },
  21483.  
  21484. get rootDOMNode()
  21485. {
  21486. return this._rootDOMNode;
  21487. },
  21488.  
  21489. set rootDOMNode(x)
  21490. {
  21491. if (this._rootDOMNode === x)
  21492. return;
  21493.  
  21494. this._rootDOMNode = x;
  21495.  
  21496. this._isXMLMimeType = x && x.isXMLNode();
  21497.  
  21498. this.update();
  21499. },
  21500.  
  21501. get isXMLMimeType()
  21502. {
  21503. return this._isXMLMimeType;
  21504. },
  21505.  
  21506. selectedDOMNode: function()
  21507. {
  21508. return this._selectedDOMNode;
  21509. },
  21510.  
  21511. selectDOMNode: function(node, focus)
  21512. {
  21513. if (this._selectedDOMNode === node) {
  21514. this._revealAndSelectNode(node, !focus);
  21515. return;
  21516. }
  21517.  
  21518. this._selectedDOMNode = node;
  21519. this._revealAndSelectNode(node, !focus);
  21520.  
  21521.  
  21522.  
  21523.  
  21524.  
  21525. if (this._selectedDOMNode === node)
  21526. this._selectedNodeChanged();
  21527. },
  21528.  
  21529. update: function()
  21530. {
  21531. var selectedNode = this.selectedTreeElement ? this.selectedTreeElement.representedObject : null;
  21532.  
  21533. this.removeChildren();
  21534.  
  21535. if (!this.rootDOMNode)
  21536. return;
  21537.  
  21538. var treeElement;
  21539. if (this._includeRootDOMNode) {
  21540. treeElement = new WebInspector.ElementsTreeElement(this.rootDOMNode);
  21541. treeElement.selectable = this._selectEnabled;
  21542. this.appendChild(treeElement);
  21543. } else {
  21544.  
  21545. var node = this.rootDOMNode.firstChild;
  21546. while (node) {
  21547. treeElement = new WebInspector.ElementsTreeElement(node);
  21548. treeElement.selectable = this._selectEnabled;
  21549. this.appendChild(treeElement);
  21550. node = node.nextSibling;
  21551. }
  21552. }
  21553.  
  21554. if (selectedNode)
  21555. this._revealAndSelectNode(selectedNode, true);
  21556. },
  21557.  
  21558. updateSelection: function()
  21559. {
  21560. if (!this.selectedTreeElement)
  21561. return;
  21562. var element = this.treeOutline.selectedTreeElement;
  21563. element.updateSelection();
  21564. },
  21565.  
  21566.  
  21567. updateOpenCloseTags: function(node)
  21568. {
  21569. var treeElement = this.findTreeElement(node);
  21570. if (treeElement)
  21571. treeElement.updateTitle();
  21572. var children = treeElement.children;
  21573. var closingTagElement = children[children.length - 1];
  21574. if (closingTagElement && closingTagElement._elementCloseTag)
  21575. closingTagElement.updateTitle();
  21576. },
  21577.  
  21578. _selectedNodeChanged: function()
  21579. {
  21580. this._eventSupport.dispatchEventToListeners(WebInspector.ElementsTreeOutline.Events.SelectedNodeChanged, this._selectedDOMNode);
  21581. },
  21582.  
  21583.  
  21584. findTreeElement: function(node)
  21585. {
  21586. function isAncestorNode(ancestor, node)
  21587. {
  21588. return ancestor.isAncestor(node);
  21589. }
  21590.  
  21591. function parentNode(node)
  21592. {
  21593. return node.parentNode;
  21594. }
  21595.  
  21596. var treeElement = TreeOutline.prototype.findTreeElement.call(this, node, isAncestorNode, parentNode);
  21597. if (!treeElement && node.nodeType() === Node.TEXT_NODE) {
  21598.  
  21599. treeElement = TreeOutline.prototype.findTreeElement.call(this, node.parentNode, isAncestorNode, parentNode);
  21600. }
  21601.  
  21602. return treeElement;
  21603. },
  21604.  
  21605.  
  21606. createTreeElementFor: function(node)
  21607. {
  21608. var treeElement = this.findTreeElement(node);
  21609. if (treeElement)
  21610. return treeElement;
  21611. if (!node.parentNode)
  21612. return null;
  21613.  
  21614. treeElement = this.createTreeElementFor(node.parentNode);
  21615. if (treeElement && treeElement.showChild(node.index))
  21616. return treeElement.children[node.index];
  21617.  
  21618. return null;
  21619. },
  21620.  
  21621. set suppressRevealAndSelect(x)
  21622. {
  21623. if (this._suppressRevealAndSelect === x)
  21624. return;
  21625. this._suppressRevealAndSelect = x;
  21626. },
  21627.  
  21628. _revealAndSelectNode: function(node, omitFocus)
  21629. {
  21630. if (!node || this._suppressRevealAndSelect)
  21631. return;
  21632.  
  21633. var treeElement = this.createTreeElementFor(node);
  21634. if (!treeElement)
  21635. return;
  21636.  
  21637. treeElement.revealAndSelect(omitFocus);
  21638. },
  21639.  
  21640. _treeElementFromEvent: function(event)
  21641. {
  21642. var scrollContainer = this.element.parentElement;
  21643.  
  21644.  
  21645.  
  21646.  
  21647.  
  21648. var x = scrollContainer.totalOffsetLeft() + scrollContainer.offsetWidth - 36;
  21649.  
  21650. var y = event.pageY;
  21651.  
  21652.  
  21653.  
  21654.  
  21655. var elementUnderMouse = this.treeElementFromPoint(x, y);
  21656. var elementAboveMouse = this.treeElementFromPoint(x, y - 2);
  21657. var element;
  21658. if (elementUnderMouse === elementAboveMouse)
  21659. element = elementUnderMouse;
  21660. else
  21661. element = this.treeElementFromPoint(x, y + 2);
  21662.  
  21663. return element;
  21664. },
  21665.  
  21666. _onmousedown: function(event)
  21667. {
  21668. var element = this._treeElementFromEvent(event);
  21669.  
  21670. if (!element || element.isEventWithinDisclosureTriangle(event))
  21671. return;
  21672.  
  21673. element.select();
  21674. },
  21675.  
  21676. _onmousemove: function(event)
  21677. {
  21678. var element = this._treeElementFromEvent(event);
  21679. if (element && this._previousHoveredElement === element)
  21680. return;
  21681.  
  21682. if (this._previousHoveredElement) {
  21683. this._previousHoveredElement.hovered = false;
  21684. delete this._previousHoveredElement;
  21685. }
  21686.  
  21687. if (element) {
  21688. element.hovered = true;
  21689. this._previousHoveredElement = element;
  21690. }
  21691.  
  21692. WebInspector.domAgent.highlightDOMNode(element ? element.representedObject.id : 0);
  21693. },
  21694.  
  21695. _onmouseout: function(event)
  21696. {
  21697. var nodeUnderMouse = document.elementFromPoint(event.pageX, event.pageY);
  21698. if (nodeUnderMouse && nodeUnderMouse.isDescendant(this.element))
  21699. return;
  21700.  
  21701. if (this._previousHoveredElement) {
  21702. this._previousHoveredElement.hovered = false;
  21703. delete this._previousHoveredElement;
  21704. }
  21705.  
  21706. WebInspector.domAgent.hideDOMNodeHighlight();
  21707. },
  21708.  
  21709. _ondragstart: function(event)
  21710. {
  21711. if (!window.getSelection().isCollapsed)
  21712. return false;
  21713. if (event.target.nodeName === "A")
  21714. return false;
  21715.  
  21716. var treeElement = this._treeElementFromEvent(event);
  21717. if (!treeElement)
  21718. return false;
  21719.  
  21720. if (!this._isValidDragSourceOrTarget(treeElement))
  21721. return false;
  21722.  
  21723. if (treeElement.representedObject.nodeName() === "BODY" || treeElement.representedObject.nodeName() === "HEAD")
  21724. return false;
  21725.  
  21726. event.dataTransfer.setData("text/plain", treeElement.listItemElement.textContent);
  21727. event.dataTransfer.effectAllowed = "copyMove";
  21728. this._treeElementBeingDragged = treeElement;
  21729.  
  21730. WebInspector.domAgent.hideDOMNodeHighlight();
  21731.  
  21732. return true;
  21733. },
  21734.  
  21735. _ondragover: function(event)
  21736. {
  21737. if (!this._treeElementBeingDragged)
  21738. return false;
  21739.  
  21740. var treeElement = this._treeElementFromEvent(event);
  21741. if (!this._isValidDragSourceOrTarget(treeElement))
  21742. return false;
  21743.  
  21744. var node = treeElement.representedObject;
  21745. while (node) {
  21746. if (node === this._treeElementBeingDragged.representedObject)
  21747. return false;
  21748. node = node.parentNode;
  21749. }
  21750.  
  21751. treeElement.updateSelection();
  21752. treeElement.listItemElement.addStyleClass("elements-drag-over");
  21753. this._dragOverTreeElement = treeElement;
  21754. event.preventDefault();
  21755. event.dataTransfer.dropEffect = 'move';
  21756. return false;
  21757. },
  21758.  
  21759. _ondragleave: function(event)
  21760. {
  21761. this._clearDragOverTreeElementMarker();
  21762. event.preventDefault();
  21763. return false;
  21764. },
  21765.  
  21766. _isValidDragSourceOrTarget: function(treeElement)
  21767. {
  21768. if (!treeElement)
  21769. return false;
  21770.  
  21771. var node = treeElement.representedObject;
  21772. if (!(node instanceof WebInspector.DOMNode))
  21773. return false;
  21774.  
  21775. if (!node.parentNode || node.parentNode.nodeType() !== Node.ELEMENT_NODE)
  21776. return false;
  21777.  
  21778. return true;
  21779. },
  21780.  
  21781. _ondrop: function(event)
  21782. {
  21783. event.preventDefault();
  21784. var treeElement = this._treeElementFromEvent(event);
  21785. if (treeElement)
  21786. this._doMove(treeElement);
  21787. },
  21788.  
  21789. _doMove: function(treeElement)
  21790. {
  21791. if (!this._treeElementBeingDragged)
  21792. return;
  21793.  
  21794. var parentNode;
  21795. var anchorNode;
  21796.  
  21797. if (treeElement._elementCloseTag) {
  21798.  
  21799. parentNode = treeElement.representedObject;
  21800. } else {
  21801. var dragTargetNode = treeElement.representedObject;
  21802. parentNode = dragTargetNode.parentNode;
  21803. anchorNode = dragTargetNode;
  21804. }
  21805.  
  21806. var wasExpanded = this._treeElementBeingDragged.expanded;
  21807. this._treeElementBeingDragged.representedObject.moveTo(parentNode, anchorNode, this._selectNodeAfterEdit.bind(this, null, wasExpanded));
  21808.  
  21809. delete this._treeElementBeingDragged;
  21810. },
  21811.  
  21812. _ondragend: function(event)
  21813. {
  21814. event.preventDefault();
  21815. this._clearDragOverTreeElementMarker();
  21816. delete this._treeElementBeingDragged;
  21817. },
  21818.  
  21819. _clearDragOverTreeElementMarker: function()
  21820. {
  21821. if (this._dragOverTreeElement) {
  21822. this._dragOverTreeElement.updateSelection();
  21823. this._dragOverTreeElement.listItemElement.removeStyleClass("elements-drag-over");
  21824. delete this._dragOverTreeElement;
  21825. }
  21826. },
  21827.  
  21828.  
  21829. _onkeydown: function(event)
  21830. {
  21831. var keyboardEvent =   (event);
  21832. var node = this.selectedDOMNode();
  21833. var treeElement = this.getCachedTreeElement(node);
  21834. if (!treeElement)
  21835. return;
  21836.  
  21837. if (!treeElement._editing && WebInspector.KeyboardShortcut.hasNoModifiers(keyboardEvent) && keyboardEvent.keyCode === WebInspector.KeyboardShortcut.Keys.H.code) {
  21838. WebInspector.cssModel.toggleInlineVisibility(node.id);
  21839. event.consume(true);
  21840. return;
  21841. }
  21842. },
  21843.  
  21844. _contextMenuEventFired: function(event)
  21845. {
  21846. if (!this._showInElementsPanelEnabled)
  21847. return;
  21848.  
  21849. var treeElement = this._treeElementFromEvent(event);
  21850. if (!treeElement)
  21851. return;
  21852.  
  21853. function focusElement()
  21854. {
  21855.  
  21856. WebInspector.showPanel("elements");
  21857. WebInspector.domAgent.inspectElement(treeElement.representedObject.id);
  21858. }
  21859. var contextMenu = new WebInspector.ContextMenu(event);
  21860. contextMenu.appendItem(WebInspector.UIString("Reveal in Elements Panel"), focusElement.bind(this));
  21861. contextMenu.show();
  21862. },
  21863.  
  21864. populateContextMenu: function(contextMenu, event)
  21865. {
  21866. var treeElement = this._treeElementFromEvent(event);
  21867. if (!treeElement)
  21868. return false;
  21869.  
  21870. var isTag = treeElement.representedObject.nodeType() === Node.ELEMENT_NODE;
  21871. var textNode = event.target.enclosingNodeOrSelfWithClass("webkit-html-text-node");
  21872. if (textNode && textNode.hasStyleClass("bogus"))
  21873. textNode = null;
  21874. var commentNode = event.target.enclosingNodeOrSelfWithClass("webkit-html-comment");
  21875. contextMenu.appendApplicableItems(event.target);
  21876. if (textNode) {
  21877. contextMenu.appendSeparator();
  21878. treeElement._populateTextContextMenu(contextMenu, textNode);
  21879. } else if (isTag) {
  21880. contextMenu.appendSeparator();
  21881. treeElement._populateTagContextMenu(contextMenu, event);
  21882. } else if (commentNode) {
  21883. contextMenu.appendSeparator();
  21884. treeElement._populateNodeContextMenu(contextMenu, textNode);
  21885. }
  21886. },
  21887.  
  21888. adjustCollapsedRange: function()
  21889. {
  21890. },
  21891.  
  21892. _updateModifiedNodes: function()
  21893. {
  21894. if (this._elementsTreeUpdater)
  21895. this._elementsTreeUpdater._updateModifiedNodes();
  21896. },
  21897.  
  21898. _populateContextMenu: function(contextMenu, node)
  21899. {
  21900. if (this._contextMenuCallback)
  21901. this._contextMenuCallback(contextMenu, node);
  21902. },
  21903.  
  21904. handleShortcut: function(event)
  21905. {
  21906. var node = this.selectedDOMNode();
  21907. var treeElement = this.getCachedTreeElement(node);
  21908. if (!node || !treeElement)
  21909. return;
  21910.  
  21911. if (event.keyIdentifier === "F2") {
  21912. this._toggleEditAsHTML(node);
  21913. event.handled = true;
  21914. return;
  21915. }
  21916.  
  21917. if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(event) && node.parentNode) {
  21918. if (event.keyIdentifier === "Up" && node.previousSibling) {
  21919. node.moveTo(node.parentNode, node.previousSibling, this._selectNodeAfterEdit.bind(this, null, treeElement.expanded));
  21920. event.handled = true;
  21921. return;
  21922. }
  21923. if (event.keyIdentifier === "Down" && node.nextSibling) {
  21924. node.moveTo(node.parentNode, node.nextSibling.nextSibling, this._selectNodeAfterEdit.bind(this, null, treeElement.expanded));
  21925. event.handled = true;
  21926. return;
  21927. }
  21928. }
  21929. },
  21930.  
  21931. _toggleEditAsHTML: function(node)
  21932. {
  21933. var treeElement = this.getCachedTreeElement(node);
  21934. if (!treeElement)
  21935. return;
  21936.  
  21937. if (treeElement._editing && treeElement._htmlEditElement && WebInspector.isBeingEdited(treeElement._htmlEditElement))
  21938. treeElement._editing.commit();
  21939. else
  21940. treeElement._editAsHTML();
  21941. },
  21942.  
  21943. _selectNodeAfterEdit: function(fallbackNode, wasExpanded, error, nodeId)
  21944. {
  21945. if (error)
  21946. return;
  21947.  
  21948.  
  21949. this._updateModifiedNodes();
  21950.  
  21951. var newNode = WebInspector.domAgent.nodeForId(nodeId) || fallbackNode;
  21952. if (!newNode)
  21953. return;
  21954.  
  21955. this.selectDOMNode(newNode, true);
  21956.  
  21957. var newTreeItem = this.findTreeElement(newNode);
  21958. if (wasExpanded) {
  21959. if (newTreeItem)
  21960. newTreeItem.expand();
  21961. }
  21962. return newTreeItem;
  21963. },
  21964.  
  21965. __proto__: TreeOutline.prototype
  21966. }
  21967.  
  21968.  
  21969. WebInspector.ElementsTreeOutline.ElementDecorator = function()
  21970. {
  21971. }
  21972.  
  21973. WebInspector.ElementsTreeOutline.ElementDecorator.prototype = {
  21974.  
  21975. decorate: function(node)
  21976. {
  21977. },
  21978.  
  21979.  
  21980. decorateAncestor: function(node)
  21981. {
  21982. }
  21983. }
  21984.  
  21985.  
  21986. WebInspector.ElementsTreeOutline.PseudoStateDecorator = function()
  21987. {
  21988. WebInspector.ElementsTreeOutline.ElementDecorator.call(this);
  21989. }
  21990.  
  21991. WebInspector.ElementsTreeOutline.PseudoStateDecorator.PropertyName = "pseudoState";
  21992.  
  21993. WebInspector.ElementsTreeOutline.PseudoStateDecorator.prototype = {
  21994. decorate: function(node)
  21995. {
  21996. if (node.nodeType() !== Node.ELEMENT_NODE)
  21997. return null;
  21998. var propertyValue = node.getUserProperty(WebInspector.ElementsTreeOutline.PseudoStateDecorator.PropertyName);
  21999. if (!propertyValue)
  22000. return null;
  22001. return WebInspector.UIString("Element state: %s", ":" + propertyValue.join(", :"));
  22002. },
  22003.  
  22004. decorateAncestor: function(node)
  22005. {
  22006. if (node.nodeType() !== Node.ELEMENT_NODE)
  22007. return null;
  22008.  
  22009. var descendantCount = node.descendantUserPropertyCount(WebInspector.ElementsTreeOutline.PseudoStateDecorator.PropertyName);
  22010. if (!descendantCount)
  22011. return null;
  22012. if (descendantCount === 1)
  22013. return WebInspector.UIString("%d descendant with forced state", descendantCount);
  22014. return WebInspector.UIString("%d descendants with forced state", descendantCount);
  22015. },
  22016.  
  22017. __proto__: WebInspector.ElementsTreeOutline.ElementDecorator.prototype
  22018. }
  22019.  
  22020.  
  22021. WebInspector.ElementsTreeElement = function(node, elementCloseTag)
  22022. {
  22023. this._elementCloseTag = elementCloseTag;
  22024. var hasChildrenOverride = !elementCloseTag && node.hasChildNodes() && !this._showInlineText(node);
  22025.  
  22026.  
  22027. TreeElement.call(this, "", node, hasChildrenOverride);
  22028.  
  22029. if (this.representedObject.nodeType() == Node.ELEMENT_NODE && !elementCloseTag)
  22030. this._canAddAttributes = true;
  22031. this._searchQuery = null;
  22032. this._expandedChildrenLimit = WebInspector.ElementsTreeElement.InitialChildrenLimit;
  22033. }
  22034.  
  22035. WebInspector.ElementsTreeElement.InitialChildrenLimit = 500;
  22036.  
  22037.  
  22038.  
  22039.  
  22040. WebInspector.ElementsTreeElement.ForbiddenClosingTagElements = [
  22041. "area", "base", "basefont", "br", "canvas", "col", "command", "embed", "frame",
  22042. "hr", "img", "input", "isindex", "keygen", "link", "meta", "param", "source"
  22043. ].keySet();
  22044.  
  22045.  
  22046. WebInspector.ElementsTreeElement.EditTagBlacklist = [
  22047. "html", "head", "body"
  22048. ].keySet();
  22049.  
  22050. WebInspector.ElementsTreeElement.prototype = {
  22051. highlightSearchResults: function(searchQuery)
  22052. {
  22053. if (this._searchQuery !== searchQuery) {
  22054. this._updateSearchHighlight(false);
  22055. delete this._highlightResult; 
  22056. }
  22057.  
  22058. this._searchQuery = searchQuery;
  22059. this._searchHighlightsVisible = true;
  22060. this.updateTitle(true);
  22061. },
  22062.  
  22063. hideSearchHighlights: function()
  22064. {
  22065. delete this._searchHighlightsVisible;
  22066. this._updateSearchHighlight(false);
  22067. },
  22068.  
  22069. _updateSearchHighlight: function(show)
  22070. {
  22071. if (!this._highlightResult)
  22072. return;
  22073.  
  22074. function updateEntryShow(entry)
  22075. {
  22076. switch (entry.type) {
  22077. case "added":
  22078. entry.parent.insertBefore(entry.node, entry.nextSibling);
  22079. break;
  22080. case "changed":
  22081. entry.node.textContent = entry.newText;
  22082. break;
  22083. }
  22084. }
  22085.  
  22086. function updateEntryHide(entry)
  22087. {
  22088. switch (entry.type) {
  22089. case "added":
  22090. if (entry.node.parentElement)
  22091. entry.node.parentElement.removeChild(entry.node);
  22092. break;
  22093. case "changed":
  22094. entry.node.textContent = entry.oldText;
  22095. break;
  22096. }
  22097. }
  22098.  
  22099.  
  22100. if (show) {
  22101. for (var i = 0, size = this._highlightResult.length; i < size; ++i)
  22102. updateEntryShow(this._highlightResult[i]);
  22103. } else {
  22104. for (var i = (this._highlightResult.length - 1); i >= 0; --i)
  22105. updateEntryHide(this._highlightResult[i]);
  22106. }
  22107. },
  22108.  
  22109. get hovered()
  22110. {
  22111. return this._hovered;
  22112. },
  22113.  
  22114. set hovered(x)
  22115. {
  22116. if (this._hovered === x)
  22117. return;
  22118.  
  22119. this._hovered = x;
  22120.  
  22121. if (this.listItemElement) {
  22122. if (x) {
  22123. this.updateSelection();
  22124. this.listItemElement.addStyleClass("hovered");
  22125. } else {
  22126. this.listItemElement.removeStyleClass("hovered");
  22127. }
  22128. }
  22129. },
  22130.  
  22131. get expandedChildrenLimit()
  22132. {
  22133. return this._expandedChildrenLimit;
  22134. },
  22135.  
  22136. set expandedChildrenLimit(x)
  22137. {
  22138. if (this._expandedChildrenLimit === x)
  22139. return;
  22140.  
  22141. this._expandedChildrenLimit = x;
  22142. if (this.treeOutline && !this._updateChildrenInProgress)
  22143. this._updateChildren(true);
  22144. },
  22145.  
  22146. get expandedChildCount()
  22147. {
  22148. var count = this.children.length;
  22149. if (count && this.children[count - 1]._elementCloseTag)
  22150. count--;
  22151. if (count && this.children[count - 1].expandAllButton)
  22152. count--;
  22153. return count;
  22154. },
  22155.  
  22156. showChild: function(index)
  22157. {
  22158. if (this._elementCloseTag)
  22159. return;
  22160.  
  22161. if (index >= this.expandedChildrenLimit) {
  22162. this._expandedChildrenLimit = index + 1;
  22163. this._updateChildren(true);
  22164. }
  22165.  
  22166.  
  22167. return this.expandedChildCount > index;
  22168. },
  22169.  
  22170. updateSelection: function()
  22171. {
  22172. var listItemElement = this.listItemElement;
  22173. if (!listItemElement)
  22174. return;
  22175.  
  22176. if (!this._readyToUpdateSelection) {
  22177. if (document.body.offsetWidth > 0)
  22178. this._readyToUpdateSelection = true;
  22179. else {
  22180.  
  22181.  
  22182. return;
  22183. }
  22184. }
  22185.  
  22186. if (!this.selectionElement) {
  22187. this.selectionElement = document.createElement("div");
  22188. this.selectionElement.className = "selection selected";
  22189. listItemElement.insertBefore(this.selectionElement, listItemElement.firstChild);
  22190. }
  22191.  
  22192. this.selectionElement.style.height = listItemElement.offsetHeight + "px";
  22193. },
  22194.  
  22195. onattach: function()
  22196. {
  22197. if (this._hovered) {
  22198. this.updateSelection();
  22199. this.listItemElement.addStyleClass("hovered");
  22200. }
  22201.  
  22202. this.updateTitle();
  22203. this._preventFollowingLinksOnDoubleClick();
  22204. this.listItemElement.draggable = true;
  22205. },
  22206.  
  22207. _preventFollowingLinksOnDoubleClick: function()
  22208. {
  22209. var links = this.listItemElement.querySelectorAll("li > .webkit-html-tag > .webkit-html-attribute > .webkit-html-external-link, li > .webkit-html-tag > .webkit-html-attribute > .webkit-html-resource-link");
  22210. if (!links)
  22211. return;
  22212.  
  22213. for (var i = 0; i < links.length; ++i)
  22214. links[i].preventFollowOnDoubleClick = true;
  22215. },
  22216.  
  22217. onpopulate: function()
  22218. {
  22219. if (this.children.length || this._showInlineText(this.representedObject) || this._elementCloseTag)
  22220. return;
  22221.  
  22222. this.updateChildren();
  22223. },
  22224.  
  22225.  
  22226. updateChildren: function(fullRefresh)
  22227. {
  22228. if (this._elementCloseTag)
  22229. return;
  22230. this.representedObject.getChildNodes(this._updateChildren.bind(this, fullRefresh));
  22231. },
  22232.  
  22233.  
  22234. insertChildElement: function(child, index, closingTag)
  22235. {
  22236. var newElement = new WebInspector.ElementsTreeElement(child, closingTag);
  22237. newElement.selectable = this.treeOutline._selectEnabled;
  22238. this.insertChild(newElement, index);
  22239. return newElement;
  22240. },
  22241.  
  22242. moveChild: function(child, targetIndex)
  22243. {
  22244. var wasSelected = child.selected;
  22245. this.removeChild(child);
  22246. this.insertChild(child, targetIndex);
  22247. if (wasSelected)
  22248. child.select();
  22249. },
  22250.  
  22251.  
  22252. _updateChildren: function(fullRefresh)
  22253. {
  22254. if (this._updateChildrenInProgress || !this.treeOutline._visible)
  22255. return;
  22256.  
  22257. this._updateChildrenInProgress = true;
  22258. var selectedNode = this.treeOutline.selectedDOMNode();
  22259. var originalScrollTop = 0;
  22260. if (fullRefresh) {
  22261. var treeOutlineContainerElement = this.treeOutline.element.parentNode;
  22262. originalScrollTop = treeOutlineContainerElement.scrollTop;
  22263. var selectedTreeElement = this.treeOutline.selectedTreeElement;
  22264. if (selectedTreeElement && selectedTreeElement.hasAncestor(this))
  22265. this.select();
  22266. this.removeChildren();
  22267. }
  22268.  
  22269. var treeElement = this;
  22270. var treeChildIndex = 0;
  22271. var elementToSelect;
  22272.  
  22273. function updateChildrenOfNode(node)
  22274. {
  22275. var treeOutline = treeElement.treeOutline;
  22276. var child = node.firstChild;
  22277. while (child) {
  22278. var currentTreeElement = treeElement.children[treeChildIndex];
  22279. if (!currentTreeElement || currentTreeElement.representedObject !== child) {
  22280.  
  22281. var existingTreeElement = null;
  22282. for (var i = (treeChildIndex + 1), size = treeElement.expandedChildCount; i < size; ++i) {
  22283. if (treeElement.children[i].representedObject === child) {
  22284. existingTreeElement = treeElement.children[i];
  22285. break;
  22286. }
  22287. }
  22288.  
  22289. if (existingTreeElement && existingTreeElement.parent === treeElement) {
  22290.  
  22291. treeElement.moveChild(existingTreeElement, treeChildIndex);
  22292. } else {
  22293.  
  22294. if (treeChildIndex < treeElement.expandedChildrenLimit) {
  22295. var newElement = treeElement.insertChildElement(child, treeChildIndex);
  22296. if (child === selectedNode)
  22297. elementToSelect = newElement;
  22298. if (treeElement.expandedChildCount > treeElement.expandedChildrenLimit)
  22299. treeElement.expandedChildrenLimit++;
  22300. }
  22301. }
  22302. }
  22303.  
  22304. child = child.nextSibling;
  22305. ++treeChildIndex;
  22306. }
  22307. }
  22308.  
  22309.  
  22310. for (var i = (this.children.length - 1); i >= 0; --i) {
  22311. var currentChild = this.children[i];
  22312. var currentNode = currentChild.representedObject;
  22313. var currentParentNode = currentNode.parentNode;
  22314.  
  22315. if (currentParentNode === this.representedObject)
  22316. continue;
  22317.  
  22318. var selectedTreeElement = this.treeOutline.selectedTreeElement;
  22319. if (selectedTreeElement && (selectedTreeElement === currentChild || selectedTreeElement.hasAncestor(currentChild)))
  22320. this.select();
  22321.  
  22322. this.removeChildAtIndex(i);
  22323. }
  22324.  
  22325. updateChildrenOfNode(this.representedObject);
  22326. this.adjustCollapsedRange();
  22327.  
  22328. var lastChild = this.children[this.children.length - 1];
  22329. if (this.representedObject.nodeType() == Node.ELEMENT_NODE && (!lastChild || !lastChild._elementCloseTag))
  22330. this.insertChildElement(this.representedObject, this.children.length, true);
  22331.  
  22332.  
  22333. if (fullRefresh && elementToSelect) {
  22334. elementToSelect.select();
  22335. if (treeOutlineContainerElement && originalScrollTop <= treeOutlineContainerElement.scrollHeight)
  22336. treeOutlineContainerElement.scrollTop = originalScrollTop;
  22337. }
  22338.  
  22339. delete this._updateChildrenInProgress;
  22340. },
  22341.  
  22342. adjustCollapsedRange: function()
  22343. {
  22344.  
  22345.  
  22346. if (this.expandAllButtonElement && this.expandAllButtonElement.__treeElement.parent)
  22347. this.removeChild(this.expandAllButtonElement.__treeElement);
  22348.  
  22349. const node = this.representedObject;
  22350. if (!node.children)
  22351. return;
  22352. const childNodeCount = node.children.length;
  22353.  
  22354.  
  22355. for (var i = this.expandedChildCount, limit = Math.min(this.expandedChildrenLimit, childNodeCount); i < limit; ++i)
  22356. this.insertChildElement(node.children[i], i);
  22357.  
  22358. const expandedChildCount = this.expandedChildCount;
  22359. if (childNodeCount > this.expandedChildCount) {
  22360. var targetButtonIndex = expandedChildCount;
  22361. if (!this.expandAllButtonElement) {
  22362. var button = document.createElement("button");
  22363. button.className = "show-all-nodes";
  22364. button.value = "";
  22365. var item = new TreeElement(button, null, false);
  22366. item.selectable = false;
  22367. item.expandAllButton = true;
  22368. this.insertChild(item, targetButtonIndex);
  22369. this.expandAllButtonElement = item.listItemElement.firstChild;
  22370. this.expandAllButtonElement.__treeElement = item;
  22371. this.expandAllButtonElement.addEventListener("click", this.handleLoadAllChildren.bind(this), false);
  22372. } else if (!this.expandAllButtonElement.__treeElement.parent)
  22373. this.insertChild(this.expandAllButtonElement.__treeElement, targetButtonIndex);
  22374. this.expandAllButtonElement.textContent = WebInspector.UIString("Show All Nodes (%d More)", childNodeCount - expandedChildCount);
  22375. } else if (this.expandAllButtonElement)
  22376. delete this.expandAllButtonElement;
  22377. },
  22378.  
  22379. handleLoadAllChildren: function()
  22380. {
  22381. this.expandedChildrenLimit = Math.max(this.representedObject._childNodeCount, this.expandedChildrenLimit + WebInspector.ElementsTreeElement.InitialChildrenLimit);
  22382. },
  22383.  
  22384. onexpand: function()
  22385. {
  22386. if (this._elementCloseTag)
  22387. return;
  22388.  
  22389. this.updateTitle();
  22390. this.treeOutline.updateSelection();
  22391. },
  22392.  
  22393. oncollapse: function()
  22394. {
  22395. if (this._elementCloseTag)
  22396. return;
  22397.  
  22398. this.updateTitle();
  22399. this.treeOutline.updateSelection();
  22400. },
  22401.  
  22402. onreveal: function()
  22403. {
  22404. if (this.listItemElement) {
  22405. var tagSpans = this.listItemElement.getElementsByClassName("webkit-html-tag-name");
  22406. if (tagSpans.length)
  22407. tagSpans[0].scrollIntoViewIfNeeded(false);
  22408. else
  22409. this.listItemElement.scrollIntoViewIfNeeded(false);
  22410. }
  22411. },
  22412.  
  22413. onselect: function(selectedByUser)
  22414. {
  22415. this.treeOutline.suppressRevealAndSelect = true;
  22416. this.treeOutline.selectDOMNode(this.representedObject, selectedByUser);
  22417. if (selectedByUser)
  22418. WebInspector.domAgent.highlightDOMNode(this.representedObject.id);
  22419. this.updateSelection();
  22420. this.treeOutline.suppressRevealAndSelect = false;
  22421. return true;
  22422. },
  22423.  
  22424. ondelete: function()
  22425. {
  22426. var startTagTreeElement = this.treeOutline.findTreeElement(this.representedObject);
  22427. startTagTreeElement ? startTagTreeElement.remove() : this.remove();
  22428. return true;
  22429. },
  22430.  
  22431. onenter: function()
  22432. {
  22433.  
  22434.  
  22435. if (this._editing)
  22436. return false;
  22437.  
  22438. this._startEditing();
  22439.  
  22440.  
  22441. return true;
  22442. },
  22443.  
  22444. selectOnMouseDown: function(event)
  22445. {
  22446. TreeElement.prototype.selectOnMouseDown.call(this, event);
  22447.  
  22448. if (this._editing)
  22449. return;
  22450.  
  22451. if (this.treeOutline._showInElementsPanelEnabled) {
  22452. WebInspector.showPanel("elements");
  22453. this.treeOutline.selectDOMNode(this.representedObject, true);
  22454. }
  22455.  
  22456.  
  22457. if (event.detail >= 2)
  22458. event.preventDefault();
  22459. },
  22460.  
  22461. ondblclick: function(event)
  22462. {
  22463. if (this._editing || this._elementCloseTag)
  22464. return;
  22465.  
  22466. if (this._startEditingTarget(event.target))
  22467. return;
  22468.  
  22469. if (this.hasChildren && !this.expanded)
  22470. this.expand();
  22471. },
  22472.  
  22473. _insertInLastAttributePosition: function(tag, node)
  22474. {
  22475. if (tag.getElementsByClassName("webkit-html-attribute").length > 0)
  22476. tag.insertBefore(node, tag.lastChild);
  22477. else {
  22478. var nodeName = tag.textContent.match(/^<(.*?)>$/)[1];
  22479. tag.textContent = '';
  22480. tag.appendChild(document.createTextNode('<'+nodeName));
  22481. tag.appendChild(node);
  22482. tag.appendChild(document.createTextNode('>'));
  22483. }
  22484.  
  22485. this.updateSelection();
  22486. },
  22487.  
  22488. _startEditingTarget: function(eventTarget)
  22489. {
  22490. if (this.treeOutline.selectedDOMNode() != this.representedObject)
  22491. return;
  22492.  
  22493. if (this.representedObject.nodeType() != Node.ELEMENT_NODE && this.representedObject.nodeType() != Node.TEXT_NODE)
  22494. return false;
  22495.  
  22496. var textNode = eventTarget.enclosingNodeOrSelfWithClass("webkit-html-text-node");
  22497. if (textNode)
  22498. return this._startEditingTextNode(textNode);
  22499.  
  22500. var attribute = eventTarget.enclosingNodeOrSelfWithClass("webkit-html-attribute");
  22501. if (attribute)
  22502. return this._startEditingAttribute(attribute, eventTarget);
  22503.  
  22504. var tagName = eventTarget.enclosingNodeOrSelfWithClass("webkit-html-tag-name");
  22505. if (tagName)
  22506. return this._startEditingTagName(tagName);
  22507.  
  22508. var newAttribute = eventTarget.enclosingNodeOrSelfWithClass("add-attribute");
  22509. if (newAttribute)
  22510. return this._addNewAttribute();
  22511.  
  22512. return false;
  22513. },
  22514.  
  22515. _populateTagContextMenu: function(contextMenu, event)
  22516. {
  22517. var attribute = event.target.enclosingNodeOrSelfWithClass("webkit-html-attribute");
  22518. var newAttribute = event.target.enclosingNodeOrSelfWithClass("add-attribute");
  22519.  
  22520.  
  22521. var treeElement = this._elementCloseTag ? this.treeOutline.findTreeElement(this.representedObject) : this;
  22522. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Add attribute" : "Add Attribute"), this._addNewAttribute.bind(treeElement));
  22523. if (attribute && !newAttribute)
  22524. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Edit attribute" : "Edit Attribute"), this._startEditingAttribute.bind(this, attribute, event.target));
  22525. contextMenu.appendSeparator();
  22526. if (this.treeOutline._setPseudoClassCallback) {
  22527. var pseudoSubMenu = contextMenu.appendSubMenuItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Force element state" : "Force Element State"));
  22528. this._populateForcedPseudoStateItems(pseudoSubMenu);
  22529. contextMenu.appendSeparator();
  22530. }
  22531.  
  22532. this._populateNodeContextMenu(contextMenu);
  22533. this.treeOutline._populateContextMenu(contextMenu, this.representedObject);
  22534.  
  22535. contextMenu.appendSeparator();
  22536. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Scroll into view" : "Scroll Into View"), this._scrollIntoView.bind(this)); 
  22537. },
  22538.  
  22539. _populateForcedPseudoStateItems: function(subMenu)
  22540. {
  22541. const pseudoClasses = ["active", "hover", "focus", "visited"];
  22542. var node = this.representedObject;
  22543. var forcedPseudoState = (node ? node.getUserProperty("pseudoState") : null) || [];
  22544. for (var i = 0; i < pseudoClasses.length; ++i) {
  22545. var pseudoClassForced = forcedPseudoState.indexOf(pseudoClasses[i]) >= 0;
  22546. subMenu.appendCheckboxItem(":" + pseudoClasses[i], this.treeOutline._setPseudoClassCallback.bind(null, node.id, pseudoClasses[i], !pseudoClassForced), pseudoClassForced, false);
  22547. }
  22548. },
  22549.  
  22550. _populateTextContextMenu: function(contextMenu, textNode)
  22551. {
  22552. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Edit text" : "Edit Text"), this._startEditingTextNode.bind(this, textNode));
  22553. this._populateNodeContextMenu(contextMenu);
  22554. },
  22555.  
  22556. _populateNodeContextMenu: function(contextMenu)
  22557. {
  22558.  
  22559. contextMenu.appendItem(WebInspector.UIString("Edit as HTML"), this._editAsHTML.bind(this));
  22560. contextMenu.appendItem(WebInspector.UIString("Copy as HTML"), this._copyHTML.bind(this));
  22561. contextMenu.appendItem(WebInspector.UIString("Copy XPath"), this._copyXPath.bind(this));
  22562. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Delete node" : "Delete Node"), this.remove.bind(this));
  22563. },
  22564.  
  22565. _startEditing: function()
  22566. {
  22567. if (this.treeOutline.selectedDOMNode() !== this.representedObject)
  22568. return;
  22569.  
  22570. var listItem = this._listItemNode;
  22571.  
  22572. if (this._canAddAttributes) {
  22573. var attribute = listItem.getElementsByClassName("webkit-html-attribute")[0];
  22574. if (attribute)
  22575. return this._startEditingAttribute(attribute, attribute.getElementsByClassName("webkit-html-attribute-value")[0]);
  22576.  
  22577. return this._addNewAttribute();
  22578. }
  22579.  
  22580. if (this.representedObject.nodeType() === Node.TEXT_NODE) {
  22581. var textNode = listItem.getElementsByClassName("webkit-html-text-node")[0];
  22582. if (textNode)
  22583. return this._startEditingTextNode(textNode);
  22584. return;
  22585. }
  22586. },
  22587.  
  22588. _addNewAttribute: function()
  22589. {
  22590.  
  22591.  
  22592. var container = document.createElement("span");
  22593. this._buildAttributeDOM(container, " ", "");
  22594. var attr = container.firstChild;
  22595. attr.style.marginLeft = "2px"; 
  22596. attr.style.marginRight = "2px"; 
  22597.  
  22598. var tag = this.listItemElement.getElementsByClassName("webkit-html-tag")[0];
  22599. this._insertInLastAttributePosition(tag, attr);
  22600. attr.scrollIntoViewIfNeeded(true);
  22601. return this._startEditingAttribute(attr, attr);
  22602. },
  22603.  
  22604. _triggerEditAttribute: function(attributeName)
  22605. {
  22606. var attributeElements = this.listItemElement.getElementsByClassName("webkit-html-attribute-name");
  22607. for (var i = 0, len = attributeElements.length; i < len; ++i) {
  22608. if (attributeElements[i].textContent === attributeName) {
  22609. for (var elem = attributeElements[i].nextSibling; elem; elem = elem.nextSibling) {
  22610. if (elem.nodeType !== Node.ELEMENT_NODE)
  22611. continue;
  22612.  
  22613. if (elem.hasStyleClass("webkit-html-attribute-value"))
  22614. return this._startEditingAttribute(elem.parentNode, elem);
  22615. }
  22616. }
  22617. }
  22618. },
  22619.  
  22620. _startEditingAttribute: function(attribute, elementForSelection)
  22621. {
  22622. if (WebInspector.isBeingEdited(attribute))
  22623. return true;
  22624.  
  22625. var attributeNameElement = attribute.getElementsByClassName("webkit-html-attribute-name")[0];
  22626. if (!attributeNameElement)
  22627. return false;
  22628.  
  22629. var attributeName = attributeNameElement.textContent;
  22630.  
  22631. function removeZeroWidthSpaceRecursive(node)
  22632. {
  22633. if (node.nodeType === Node.TEXT_NODE) {
  22634. node.nodeValue = node.nodeValue.replace(/\u200B/g, "");
  22635. return;
  22636. }
  22637.  
  22638. if (node.nodeType !== Node.ELEMENT_NODE)
  22639. return;
  22640.  
  22641. for (var child = node.firstChild; child; child = child.nextSibling)
  22642. removeZeroWidthSpaceRecursive(child);
  22643. }
  22644.  
  22645.  
  22646. removeZeroWidthSpaceRecursive(attribute);
  22647.  
  22648. var config = new WebInspector.EditingConfig(this._attributeEditingCommitted.bind(this), this._editingCancelled.bind(this), attributeName);
  22649.  
  22650. function handleKeyDownEvents(event)
  22651. {
  22652. var isMetaOrCtrl = WebInspector.isMac() ?
  22653. event.metaKey && !event.shiftKey && !event.ctrlKey && !event.altKey :
  22654. event.ctrlKey && !event.shiftKey && !event.metaKey && !event.altKey;
  22655. if (isEnterKey(event) && (event.isMetaOrCtrlForTest || !config.multiline || isMetaOrCtrl))
  22656. return "commit";
  22657. else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code || event.keyIdentifier === "U+001B")
  22658. return "cancel";
  22659. else if (event.keyIdentifier === "U+0009") 
  22660. return "move-" + (event.shiftKey ? "backward" : "forward");
  22661. else {
  22662. WebInspector.handleElementValueModifications(event, attribute);
  22663. return "";
  22664. }
  22665. }
  22666.  
  22667. config.customFinishHandler = handleKeyDownEvents.bind(this);
  22668.  
  22669. this._editing = WebInspector.startEditing(attribute, config);
  22670.  
  22671. window.getSelection().setBaseAndExtent(elementForSelection, 0, elementForSelection, 1);
  22672.  
  22673. return true;
  22674. },
  22675.  
  22676.  
  22677. _startEditingTextNode: function(textNodeElement)
  22678. {
  22679. if (WebInspector.isBeingEdited(textNodeElement))
  22680. return true;
  22681.  
  22682. var textNode = this.representedObject;
  22683.  
  22684.  
  22685. if (textNode.nodeType() === Node.ELEMENT_NODE && textNode.firstChild)
  22686. textNode = textNode.firstChild;
  22687.  
  22688. var container = textNodeElement.enclosingNodeOrSelfWithClass("webkit-html-text-node");
  22689. if (container)
  22690. container.textContent = textNode.nodeValue(); 
  22691. var config = new WebInspector.EditingConfig(this._textNodeEditingCommitted.bind(this, textNode), this._editingCancelled.bind(this));
  22692. this._editing = WebInspector.startEditing(textNodeElement, config);
  22693. window.getSelection().setBaseAndExtent(textNodeElement, 0, textNodeElement, 1);
  22694.  
  22695. return true;
  22696. },
  22697.  
  22698.  
  22699. _startEditingTagName: function(tagNameElement)
  22700. {
  22701. if (!tagNameElement) {
  22702. tagNameElement = this.listItemElement.getElementsByClassName("webkit-html-tag-name")[0];
  22703. if (!tagNameElement)
  22704. return false;
  22705. }
  22706.  
  22707. var tagName = tagNameElement.textContent;
  22708. if (WebInspector.ElementsTreeElement.EditTagBlacklist[tagName.toLowerCase()])
  22709. return false;
  22710.  
  22711. if (WebInspector.isBeingEdited(tagNameElement))
  22712. return true;
  22713.  
  22714. var closingTagElement = this._distinctClosingTagElement();
  22715.  
  22716. function keyupListener(event)
  22717. {
  22718. if (closingTagElement)
  22719. closingTagElement.textContent = "</" + tagNameElement.textContent + ">";
  22720. }
  22721.  
  22722. function editingComitted(element, newTagName)
  22723. {
  22724. tagNameElement.removeEventListener('keyup', keyupListener, false);
  22725. this._tagNameEditingCommitted.apply(this, arguments);
  22726. }
  22727.  
  22728. function editingCancelled()
  22729. {
  22730. tagNameElement.removeEventListener('keyup', keyupListener, false);
  22731. this._editingCancelled.apply(this, arguments);
  22732. }
  22733.  
  22734. tagNameElement.addEventListener('keyup', keyupListener, false);
  22735.  
  22736. var config = new WebInspector.EditingConfig(editingComitted.bind(this), editingCancelled.bind(this), tagName);
  22737. this._editing = WebInspector.startEditing(tagNameElement, config);
  22738. window.getSelection().setBaseAndExtent(tagNameElement, 0, tagNameElement, 1);
  22739. return true;
  22740. },
  22741.  
  22742. _startEditingAsHTML: function(commitCallback, error, initialValue)
  22743. {
  22744. if (error)
  22745. return;
  22746. if (this._htmlEditElement && WebInspector.isBeingEdited(this._htmlEditElement))
  22747. return;
  22748.  
  22749. function consume(event)
  22750. {
  22751. if (event.eventPhase === Event.AT_TARGET)
  22752. event.consume(true);
  22753. }
  22754.  
  22755. initialValue = this._convertWhitespaceToEntities(initialValue);
  22756.  
  22757. this._htmlEditElement = document.createElement("div");
  22758. this._htmlEditElement.className = "source-code elements-tree-editor";
  22759. this._htmlEditElement.textContent = initialValue;
  22760.  
  22761.  
  22762. var child = this.listItemElement.firstChild;
  22763. while (child) {
  22764. child.style.display = "none";
  22765. child = child.nextSibling;
  22766. }
  22767.  
  22768. if (this._childrenListNode)
  22769. this._childrenListNode.style.display = "none";
  22770.  
  22771. this.listItemElement.appendChild(this._htmlEditElement);
  22772. this.treeOutline.childrenListElement.parentElement.addEventListener("mousedown", consume, false);
  22773.  
  22774. this.updateSelection();
  22775.  
  22776. function commit()
  22777. {
  22778. commitCallback(initialValue, this._htmlEditElement.textContent);
  22779. dispose.call(this);
  22780. }
  22781.  
  22782. function dispose()
  22783. {
  22784. delete this._editing;
  22785.  
  22786.  
  22787. this.listItemElement.removeChild(this._htmlEditElement);
  22788. delete this._htmlEditElement;
  22789.  
  22790. if (this._childrenListNode)
  22791. this._childrenListNode.style.removeProperty("display");
  22792.  
  22793. var child = this.listItemElement.firstChild;
  22794. while (child) {
  22795. child.style.removeProperty("display");
  22796. child = child.nextSibling;
  22797. }
  22798.  
  22799. this.treeOutline.childrenListElement.parentElement.removeEventListener("mousedown", consume, false);
  22800. this.updateSelection();
  22801. }
  22802.  
  22803. var config = new WebInspector.EditingConfig(commit.bind(this), dispose.bind(this));
  22804. config.setMultiline(true);
  22805. this._editing = WebInspector.startEditing(this._htmlEditElement, config);
  22806. },
  22807.  
  22808. _attributeEditingCommitted: function(element, newText, oldText, attributeName, moveDirection)
  22809. {
  22810. delete this._editing;
  22811.  
  22812. var treeOutline = this.treeOutline;
  22813.  
  22814. function moveToNextAttributeIfNeeded(error)
  22815. {
  22816. if (error)
  22817. this._editingCancelled(element, attributeName);
  22818.  
  22819. if (!moveDirection)
  22820. return;
  22821.  
  22822. treeOutline._updateModifiedNodes();
  22823.  
  22824.  
  22825. var attributes = this.representedObject.attributes();
  22826. for (var i = 0; i < attributes.length; ++i) {
  22827. if (attributes[i].name !== attributeName)
  22828. continue;
  22829.  
  22830. if (moveDirection === "backward") {
  22831. if (i === 0)
  22832. this._startEditingTagName();
  22833. else
  22834. this._triggerEditAttribute(attributes[i - 1].name);
  22835. } else {
  22836. if (i === attributes.length - 1)
  22837. this._addNewAttribute();
  22838. else
  22839. this._triggerEditAttribute(attributes[i + 1].name);
  22840. }
  22841. return;
  22842. }
  22843.  
  22844.  
  22845. if (moveDirection === "backward") {
  22846. if (newText === " ") {
  22847.  
  22848. if (attributes.length > 0)
  22849. this._triggerEditAttribute(attributes[attributes.length - 1].name);
  22850. } else {
  22851.  
  22852. if (attributes.length > 1)
  22853. this._triggerEditAttribute(attributes[attributes.length - 2].name);
  22854. }
  22855. } else if (moveDirection === "forward") {
  22856. if (!/^\s*$/.test(newText))
  22857. this._addNewAttribute();
  22858. else
  22859. this._startEditingTagName();
  22860. }
  22861. }
  22862.  
  22863. if (oldText !== newText)
  22864. this.representedObject.setAttribute(attributeName, newText, moveToNextAttributeIfNeeded.bind(this));
  22865. else
  22866. moveToNextAttributeIfNeeded.call(this);
  22867. },
  22868.  
  22869. _tagNameEditingCommitted: function(element, newText, oldText, tagName, moveDirection)
  22870. {
  22871. delete this._editing;
  22872. var self = this;
  22873.  
  22874. function cancel()
  22875. {
  22876. var closingTagElement = self._distinctClosingTagElement();
  22877. if (closingTagElement)
  22878. closingTagElement.textContent = "</" + tagName + ">";
  22879.  
  22880. self._editingCancelled(element, tagName);
  22881. moveToNextAttributeIfNeeded.call(self);
  22882. }
  22883.  
  22884. function moveToNextAttributeIfNeeded()
  22885. {
  22886. if (moveDirection !== "forward") {
  22887. this._addNewAttribute();
  22888. return;
  22889. }
  22890.  
  22891. var attributes = this.representedObject.attributes();
  22892. if (attributes.length > 0)
  22893. this._triggerEditAttribute(attributes[0].name);
  22894. else
  22895. this._addNewAttribute();
  22896. }
  22897.  
  22898. newText = newText.trim();
  22899. if (newText === oldText) {
  22900. cancel();
  22901. return;
  22902. }
  22903.  
  22904. var treeOutline = this.treeOutline;
  22905. var wasExpanded = this.expanded;
  22906.  
  22907. function changeTagNameCallback(error, nodeId)
  22908. {
  22909. if (error || !nodeId) {
  22910. cancel();
  22911. return;
  22912. }
  22913. var newTreeItem = treeOutline._selectNodeAfterEdit(null, wasExpanded, error, nodeId);
  22914. moveToNextAttributeIfNeeded.call(newTreeItem);
  22915. }
  22916.  
  22917. this.representedObject.setNodeName(newText, changeTagNameCallback);
  22918. },
  22919.  
  22920.  
  22921. _textNodeEditingCommitted: function(textNode, element, newText)
  22922. {
  22923. delete this._editing;
  22924.  
  22925. function callback()
  22926. {
  22927. this.updateTitle();
  22928. }
  22929. textNode.setNodeValue(newText, callback.bind(this));
  22930. },
  22931.  
  22932.  
  22933. _editingCancelled: function(element, context)
  22934. {
  22935. delete this._editing;
  22936.  
  22937.  
  22938. this.updateTitle();
  22939. },
  22940.  
  22941. _distinctClosingTagElement: function()
  22942. {
  22943.  
  22944.  
  22945.  
  22946.  
  22947. if (this.expanded) {
  22948. var closers = this._childrenListNode.querySelectorAll(".close");
  22949. return closers[closers.length-1];
  22950. }
  22951.  
  22952.  
  22953.  
  22954.  
  22955. var tags = this.listItemElement.getElementsByClassName("webkit-html-tag");
  22956. return (tags.length === 1 ? null : tags[tags.length-1]);
  22957. },
  22958.  
  22959.  
  22960. updateTitle: function(onlySearchQueryChanged)
  22961. {
  22962.  
  22963.  
  22964. if (this._editing)
  22965. return;
  22966.  
  22967. if (onlySearchQueryChanged) {
  22968. if (this._highlightResult)
  22969. this._updateSearchHighlight(false);
  22970. } else {
  22971. var highlightElement = document.createElement("span");
  22972. highlightElement.className = "highlight";
  22973. highlightElement.appendChild(this._nodeTitleInfo(WebInspector.linkifyURLAsNode).titleDOM);
  22974. this.title = highlightElement;
  22975. this._updateDecorations();
  22976. delete this._highlightResult;
  22977. }
  22978.  
  22979. delete this.selectionElement;
  22980. if (this.selected)
  22981. this.updateSelection();
  22982. this._preventFollowingLinksOnDoubleClick();
  22983. this._highlightSearchResults();
  22984. },
  22985.  
  22986. _createDecoratorElement: function()
  22987. {
  22988. var node = this.representedObject;
  22989. var decoratorMessages = [];
  22990. var parentDecoratorMessages = [];
  22991. for (var i = 0; i < this.treeOutline._nodeDecorators.length; ++i) {
  22992. var decorator = this.treeOutline._nodeDecorators[i];
  22993. var message = decorator.decorate(node);
  22994. if (message) {
  22995. decoratorMessages.push(message);
  22996. continue;
  22997. }
  22998.  
  22999. if (this.expanded || this._elementCloseTag)
  23000. continue;
  23001.  
  23002. message = decorator.decorateAncestor(node);
  23003. if (message)
  23004. parentDecoratorMessages.push(message)
  23005. }
  23006. if (!decoratorMessages.length && !parentDecoratorMessages.length)
  23007. return null;
  23008.  
  23009. var decoratorElement = document.createElement("div");
  23010. decoratorElement.addStyleClass("elements-gutter-decoration");
  23011. if (!decoratorMessages.length)
  23012. decoratorElement.addStyleClass("elements-has-decorated-children");
  23013. decoratorElement.title = decoratorMessages.concat(parentDecoratorMessages).join("\n");
  23014. return decoratorElement;
  23015. },
  23016.  
  23017. _updateDecorations: function()
  23018. {
  23019. if (this._decoratorElement && this._decoratorElement.parentElement)
  23020. this._decoratorElement.parentElement.removeChild(this._decoratorElement);
  23021. this._decoratorElement = this._createDecoratorElement();
  23022. if (this._decoratorElement && this.listItemElement)
  23023. this.listItemElement.insertBefore(this._decoratorElement, this.listItemElement.firstChild);
  23024. },
  23025.  
  23026.  
  23027. _buildAttributeDOM: function(parentElement, name, value, node, linkify)
  23028. {
  23029. var hasText = (value.length > 0);
  23030. var attrSpanElement = parentElement.createChild("span", "webkit-html-attribute");
  23031. var attrNameElement = attrSpanElement.createChild("span", "webkit-html-attribute-name");
  23032. attrNameElement.textContent = name;
  23033.  
  23034. if (hasText)
  23035. attrSpanElement.appendChild(document.createTextNode("=\u200B\""));
  23036.  
  23037. if (linkify && (name === "src" || name === "href")) {
  23038. var rewrittenHref = node.resolveURL(value);
  23039. value = value.replace(/([\/;:\)\]\}])/g, "$1\u200B");
  23040. if (rewrittenHref === null) {
  23041. var attrValueElement = attrSpanElement.createChild("span", "webkit-html-attribute-value");
  23042. attrValueElement.textContent = value;
  23043. } else {
  23044. if (value.startsWith("data:"))
  23045. value = value.trimMiddle(60);
  23046. attrSpanElement.appendChild(linkify(rewrittenHref, value, "webkit-html-attribute-value", node.nodeName().toLowerCase() === "a"));
  23047. }
  23048. } else {
  23049. value = value.replace(/([\/;:\)\]\}])/g, "$1\u200B");
  23050. var attrValueElement = attrSpanElement.createChild("span", "webkit-html-attribute-value");
  23051. attrValueElement.textContent = value;
  23052. }
  23053.  
  23054. if (hasText)
  23055. attrSpanElement.appendChild(document.createTextNode("\""));
  23056. },
  23057.  
  23058.  
  23059. _buildTagDOM: function(parentElement, tagName, isClosingTag, isDistinctTreeElement, linkify)
  23060. {
  23061. var node =   (this.representedObject);
  23062. var classes = [ "webkit-html-tag" ];
  23063. if (isClosingTag && isDistinctTreeElement)
  23064. classes.push("close");
  23065. if (node.isInShadowTree())
  23066. classes.push("shadow");
  23067. var tagElement = parentElement.createChild("span", classes.join(" "));
  23068. tagElement.appendChild(document.createTextNode("<"));
  23069. var tagNameElement = tagElement.createChild("span", isClosingTag ? "" : "webkit-html-tag-name");
  23070. tagNameElement.textContent = (isClosingTag ? "/" : "") + tagName;
  23071. if (!isClosingTag && node.hasAttributes()) {
  23072. var attributes = node.attributes();
  23073. for (var i = 0; i < attributes.length; ++i) {
  23074. var attr = attributes[i];
  23075. tagElement.appendChild(document.createTextNode(" "));
  23076. this._buildAttributeDOM(tagElement, attr.name, attr.value, node, linkify);
  23077. }
  23078. }
  23079. tagElement.appendChild(document.createTextNode(">"));
  23080. parentElement.appendChild(document.createTextNode("\u200B"));
  23081. },
  23082.  
  23083. _convertWhitespaceToEntities: function(text)
  23084. {
  23085. var result = "";
  23086. var lastIndexAfterEntity = 0;
  23087. var charToEntity = WebInspector.ElementsTreeOutline.MappedCharToEntity;
  23088. for (var i = 0, size = text.length; i < size; ++i) {
  23089. var char = text.charAt(i);
  23090. if (charToEntity[char]) {
  23091. result += text.substring(lastIndexAfterEntity, i) + "&" + charToEntity[char] + ";";
  23092. lastIndexAfterEntity = i + 1;
  23093. }
  23094. }
  23095. if (result) {
  23096. result += text.substring(lastIndexAfterEntity);
  23097. return result;
  23098. }
  23099. return text;
  23100. },
  23101.  
  23102. _nodeTitleInfo: function(linkify)
  23103. {
  23104. var node = this.representedObject;
  23105. var info = {titleDOM: document.createDocumentFragment(), hasChildren: this.hasChildren};
  23106.  
  23107. switch (node.nodeType()) {
  23108. case Node.ATTRIBUTE_NODE:
  23109. var value = node.value || "\u200B"; 
  23110. this._buildAttributeDOM(info.titleDOM, node.name, value);
  23111. break;
  23112.  
  23113. case Node.ELEMENT_NODE:
  23114. var tagName = node.nodeNameInCorrectCase();
  23115. if (this._elementCloseTag) {
  23116. this._buildTagDOM(info.titleDOM, tagName, true, true);
  23117. info.hasChildren = false;
  23118. break;
  23119. }
  23120.  
  23121. this._buildTagDOM(info.titleDOM, tagName, false, false, linkify);
  23122.  
  23123. var textChild = this._singleTextChild(node);
  23124. var showInlineText = textChild && textChild.nodeValue().length < Preferences.maxInlineTextChildLength && !this.hasChildren;
  23125.  
  23126. if (!this.expanded && (!showInlineText && (this.treeOutline.isXMLMimeType || !WebInspector.ElementsTreeElement.ForbiddenClosingTagElements[tagName]))) {
  23127. if (this.hasChildren) {
  23128. var textNodeElement = info.titleDOM.createChild("span", "webkit-html-text-node bogus");
  23129. textNodeElement.textContent = "\u2026";
  23130. info.titleDOM.appendChild(document.createTextNode("\u200B"));
  23131. }
  23132. this._buildTagDOM(info.titleDOM, tagName, true, false);
  23133. }
  23134.  
  23135.  
  23136.  
  23137.  
  23138. if (showInlineText) {
  23139. var textNodeElement = info.titleDOM.createChild("span", "webkit-html-text-node");
  23140. textNodeElement.textContent = this._convertWhitespaceToEntities(textChild.nodeValue());
  23141. info.titleDOM.appendChild(document.createTextNode("\u200B"));
  23142. this._buildTagDOM(info.titleDOM, tagName, true, false);
  23143. info.hasChildren = false;
  23144. }
  23145. break;
  23146.  
  23147. case Node.TEXT_NODE:
  23148. if (node.parentNode && node.parentNode.nodeName().toLowerCase() === "script") {
  23149. var newNode = info.titleDOM.createChild("span", "webkit-html-text-node webkit-html-js-node");
  23150. newNode.textContent = node.nodeValue();
  23151.  
  23152. var javascriptSyntaxHighlighter = new WebInspector.DOMSyntaxHighlighter("text/javascript", true);
  23153. javascriptSyntaxHighlighter.syntaxHighlightNode(newNode);
  23154. } else if (node.parentNode && node.parentNode.nodeName().toLowerCase() === "style") {
  23155. var newNode = info.titleDOM.createChild("span", "webkit-html-text-node webkit-html-css-node");
  23156. newNode.textContent = node.nodeValue();
  23157.  
  23158. var cssSyntaxHighlighter = new WebInspector.DOMSyntaxHighlighter("text/css", true);
  23159. cssSyntaxHighlighter.syntaxHighlightNode(newNode);
  23160. } else {
  23161. info.titleDOM.appendChild(document.createTextNode("\""));
  23162. var textNodeElement = info.titleDOM.createChild("span", "webkit-html-text-node");
  23163. textNodeElement.textContent = this._convertWhitespaceToEntities(node.nodeValue());
  23164. info.titleDOM.appendChild(document.createTextNode("\""));
  23165. }
  23166. break;
  23167.  
  23168. case Node.COMMENT_NODE:
  23169. var commentElement = info.titleDOM.createChild("span", "webkit-html-comment");
  23170. commentElement.appendChild(document.createTextNode("<!--" + node.nodeValue() + "-->"));
  23171. break;
  23172.  
  23173. case Node.DOCUMENT_TYPE_NODE:
  23174. var docTypeElement = info.titleDOM.createChild("span", "webkit-html-doctype");
  23175. docTypeElement.appendChild(document.createTextNode("<!DOCTYPE " + node.nodeName()));
  23176. if (node.publicId) {
  23177. docTypeElement.appendChild(document.createTextNode(" PUBLIC \"" + node.publicId + "\""));
  23178. if (node.systemId)
  23179. docTypeElement.appendChild(document.createTextNode(" \"" + node.systemId + "\""));
  23180. } else if (node.systemId)
  23181. docTypeElement.appendChild(document.createTextNode(" SYSTEM \"" + node.systemId + "\""));
  23182.  
  23183. if (node.internalSubset)
  23184. docTypeElement.appendChild(document.createTextNode(" [" + node.internalSubset + "]"));
  23185.  
  23186. docTypeElement.appendChild(document.createTextNode(">"));
  23187. break;
  23188.  
  23189. case Node.CDATA_SECTION_NODE:
  23190. var cdataElement = info.titleDOM.createChild("span", "webkit-html-text-node");
  23191. cdataElement.appendChild(document.createTextNode("<![CDATA[" + node.nodeValue() + "]]>"));
  23192. break;
  23193. case Node.DOCUMENT_FRAGMENT_NODE:
  23194. var fragmentElement = info.titleDOM.createChild("span", "webkit-html-fragment");
  23195. fragmentElement.textContent = node.nodeNameInCorrectCase().collapseWhitespace();
  23196. if (node.isInShadowTree())
  23197. fragmentElement.addStyleClass("shadow");
  23198. break;
  23199. default:
  23200. info.titleDOM.appendChild(document.createTextNode(node.nodeNameInCorrectCase().collapseWhitespace()));
  23201. }
  23202. return info;
  23203. },
  23204.  
  23205. _singleTextChild: function(node)
  23206. {
  23207. if (!node)
  23208. return null;
  23209.  
  23210. var firstChild = node.firstChild;
  23211. if (!firstChild || firstChild.nodeType() !== Node.TEXT_NODE)
  23212. return null;
  23213.  
  23214. if (node.hasShadowRoots())
  23215. return null;
  23216.  
  23217. var sibling = firstChild.nextSibling;
  23218. return sibling ? null : firstChild;
  23219. },
  23220.  
  23221. _showInlineText: function(node)
  23222. {
  23223. if (node.nodeType() === Node.ELEMENT_NODE) {
  23224. var textChild = this._singleTextChild(node);
  23225. if (textChild && textChild.nodeValue().length < Preferences.maxInlineTextChildLength)
  23226. return true;
  23227. }
  23228. return false;
  23229. },
  23230.  
  23231. remove: function()
  23232. {
  23233. var parentElement = this.parent;
  23234. if (!parentElement)
  23235. return;
  23236.  
  23237. var self = this;
  23238. function removeNodeCallback(error, removedNodeId)
  23239. {
  23240. if (error)
  23241. return;
  23242.  
  23243. parentElement.removeChild(self);
  23244. parentElement.adjustCollapsedRange();
  23245. }
  23246.  
  23247. if (!this.representedObject.parentNode || this.representedObject.parentNode.nodeType() === Node.DOCUMENT_NODE)
  23248. return;
  23249. this.representedObject.removeNode(removeNodeCallback);
  23250. },
  23251.  
  23252. _editAsHTML: function()
  23253. {
  23254. var treeOutline = this.treeOutline;
  23255. var node = this.representedObject;
  23256. var parentNode = node.parentNode;
  23257. var index = node.index;
  23258. var wasExpanded = this.expanded;
  23259.  
  23260. function selectNode(error, nodeId)
  23261. {
  23262. if (error)
  23263. return;
  23264.  
  23265.  
  23266. treeOutline._updateModifiedNodes();
  23267.  
  23268. var newNode = parentNode ? parentNode.children[index] || parentNode : null;
  23269. if (!newNode)
  23270. return;
  23271.  
  23272. treeOutline.selectDOMNode(newNode, true);
  23273.  
  23274. if (wasExpanded) {
  23275. var newTreeItem = treeOutline.findTreeElement(newNode);
  23276. if (newTreeItem)
  23277. newTreeItem.expand();
  23278. }
  23279. }
  23280.  
  23281. function commitChange(initialValue, value)
  23282. {
  23283. if (initialValue !== value)
  23284. node.setOuterHTML(value, selectNode);
  23285. else
  23286. return;
  23287. }
  23288.  
  23289. node.getOuterHTML(this._startEditingAsHTML.bind(this, commitChange));
  23290. },
  23291.  
  23292. _copyHTML: function()
  23293. {
  23294. this.representedObject.copyNode();
  23295. },
  23296.  
  23297. _copyXPath: function()
  23298. {
  23299. this.representedObject.copyXPath(true);
  23300. },
  23301.  
  23302. _highlightSearchResults: function()
  23303. {
  23304. if (!this._searchQuery || !this._searchHighlightsVisible)
  23305. return;
  23306. if (this._highlightResult) {
  23307. this._updateSearchHighlight(true);
  23308. return;
  23309. }
  23310.  
  23311. var text = this.listItemElement.textContent;
  23312. var regexObject = createPlainTextSearchRegex(this._searchQuery, "gi");
  23313.  
  23314. var offset = 0;
  23315. var match = regexObject.exec(text);
  23316. var matchRanges = [];
  23317. while (match) {
  23318. matchRanges.push({ offset: match.index, length: match[0].length });
  23319. match = regexObject.exec(text);
  23320. }
  23321.  
  23322.  
  23323. if (!matchRanges.length)
  23324. matchRanges.push({ offset: 0, length: text.length });
  23325.  
  23326. this._highlightResult = [];
  23327. WebInspector.highlightSearchResults(this.listItemElement, matchRanges, this._highlightResult);
  23328. },
  23329.  
  23330. _scrollIntoView: function()
  23331. {
  23332. function scrollIntoViewCallback(object)
  23333. {
  23334. function scrollIntoView()
  23335. {
  23336. this.scrollIntoViewIfNeeded(true);
  23337. }
  23338.  
  23339. if (object)
  23340. object.callFunction(scrollIntoView);
  23341. }
  23342.  
  23343. var node =   (this.representedObject);
  23344. WebInspector.RemoteObject.resolveNode(node, "", scrollIntoViewCallback);
  23345. },
  23346.  
  23347. __proto__: TreeElement.prototype
  23348. }
  23349.  
  23350.  
  23351. WebInspector.ElementsTreeUpdater = function(treeOutline)
  23352. {
  23353. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.NodeInserted, this._nodeInserted, this);
  23354. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.NodeRemoved, this._nodeRemoved, this);
  23355. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrModified, this._attributesUpdated, this);
  23356. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.AttrRemoved, this._attributesUpdated, this);
  23357. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.CharacterDataModified, this._characterDataModified, this);
  23358. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.DocumentUpdated, this._documentUpdated, this);
  23359. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.ChildNodeCountUpdated, this._childNodeCountUpdated, this);
  23360.  
  23361. this._treeOutline = treeOutline;
  23362. this._recentlyModifiedNodes = new Map();
  23363. }
  23364.  
  23365. WebInspector.ElementsTreeUpdater.prototype = {
  23366.  
  23367.  
  23368. _nodeModified: function(node, isUpdated, parentNode)
  23369. {
  23370. if (this._treeOutline._visible)
  23371. this._updateModifiedNodesSoon();
  23372.  
  23373. var entry =   (this._recentlyModifiedNodes.get(node));
  23374. if (!entry) {
  23375. entry = new WebInspector.ElementsTreeUpdater.UpdateEntry(isUpdated, parentNode);
  23376. this._recentlyModifiedNodes.put(node, entry);
  23377. return;
  23378. }
  23379.  
  23380. entry.isUpdated |= isUpdated;
  23381. if (parentNode)
  23382. entry.parent = parentNode;
  23383. },
  23384.  
  23385. _documentUpdated: function(event)
  23386. {
  23387. var inspectedRootDocument = event.data;
  23388.  
  23389. this._reset();
  23390.  
  23391. if (!inspectedRootDocument)
  23392. return;
  23393.  
  23394. this._treeOutline.rootDOMNode = inspectedRootDocument;
  23395. },
  23396.  
  23397. _attributesUpdated: function(event)
  23398. {
  23399. this._nodeModified(event.data.node, true);
  23400. },
  23401.  
  23402. _characterDataModified: function(event)
  23403. {
  23404. this._nodeModified(event.data, true);
  23405. },
  23406.  
  23407. _nodeInserted: function(event)
  23408. {
  23409. this._nodeModified(event.data, false, event.data.parentNode);
  23410. },
  23411.  
  23412. _nodeRemoved: function(event)
  23413. {
  23414. this._nodeModified(event.data.node, false, event.data.parent);
  23415. },
  23416.  
  23417. _childNodeCountUpdated: function(event)
  23418. {
  23419. var treeElement = this._treeOutline.findTreeElement(event.data);
  23420. if (treeElement)
  23421. treeElement.hasChildren = event.data.hasChildNodes();
  23422. },
  23423.  
  23424. _updateModifiedNodesSoon: function()
  23425. {
  23426. if (this._updateModifiedNodesTimeout)
  23427. return;
  23428. this._updateModifiedNodesTimeout = setTimeout(this._updateModifiedNodes.bind(this), 50);
  23429. },
  23430.  
  23431. _updateModifiedNodes: function()
  23432. {
  23433. if (this._updateModifiedNodesTimeout) {
  23434. clearTimeout(this._updateModifiedNodesTimeout);
  23435. delete this._updateModifiedNodesTimeout;
  23436. }
  23437.  
  23438. var updatedParentTreeElements = [];
  23439.  
  23440. var hidePanelWhileUpdating = this._recentlyModifiedNodes.size() > 10;
  23441. if (hidePanelWhileUpdating) {
  23442. var treeOutlineContainerElement = this._treeOutline.element.parentNode;
  23443. this._treeOutline.element.addStyleClass("hidden");
  23444. var originalScrollTop = treeOutlineContainerElement ? treeOutlineContainerElement.scrollTop : 0;
  23445. }
  23446.  
  23447. var keys = this._recentlyModifiedNodes.keys();
  23448. for (var i = 0, size = keys.length; i < size; ++i) {
  23449. var node = keys[i];
  23450. var entry = this._recentlyModifiedNodes.get(node);
  23451. var parent = entry.parent;
  23452.  
  23453. if (parent === this._treeOutline._rootDOMNode) {
  23454.  
  23455. this._treeOutline.update();
  23456. this._treeOutline.element.removeStyleClass("hidden");
  23457. return;
  23458. }
  23459.  
  23460. if (entry.isUpdated) {
  23461. var nodeItem = this._treeOutline.findTreeElement(node);
  23462. if (nodeItem)
  23463. nodeItem.updateTitle();
  23464. }
  23465.  
  23466. if (!parent)
  23467. continue;
  23468.  
  23469. var parentNodeItem = this._treeOutline.findTreeElement(parent);
  23470. if (parentNodeItem && !parentNodeItem.alreadyUpdatedChildren) {
  23471. parentNodeItem.updateChildren();
  23472. parentNodeItem.alreadyUpdatedChildren = true;
  23473. updatedParentTreeElements.push(parentNodeItem);
  23474. }
  23475. }
  23476.  
  23477. for (var i = 0; i < updatedParentTreeElements.length; ++i)
  23478. delete updatedParentTreeElements[i].alreadyUpdatedChildren;
  23479.  
  23480. if (hidePanelWhileUpdating) {
  23481. this._treeOutline.element.removeStyleClass("hidden");
  23482. if (originalScrollTop)
  23483. treeOutlineContainerElement.scrollTop = originalScrollTop;
  23484. this._treeOutline.updateSelection();
  23485. }
  23486. this._recentlyModifiedNodes.clear();
  23487. },
  23488.  
  23489. _reset: function()
  23490. {
  23491. this._treeOutline.rootDOMNode = null;
  23492. this._treeOutline.selectDOMNode(null, false);
  23493. WebInspector.domAgent.hideDOMNodeHighlight();
  23494. this._recentlyModifiedNodes.clear();
  23495. }
  23496. }
  23497.  
  23498.  
  23499. WebInspector.ElementsTreeUpdater.UpdateEntry = function(isUpdated, parent)
  23500. {
  23501. this.isUpdated = isUpdated;
  23502. if (parent)
  23503. this.parent = parent;
  23504. }
  23505.  
  23506.  
  23507.  
  23508.  
  23509.  
  23510. WebInspector.DOMPresentationUtils = {}
  23511.  
  23512. WebInspector.DOMPresentationUtils.decorateNodeLabel = function(node, parentElement)
  23513. {
  23514. var title = node.nodeNameInCorrectCase();
  23515.  
  23516. var nameElement = document.createElement("span");
  23517. nameElement.textContent = title;
  23518. parentElement.appendChild(nameElement);
  23519.  
  23520. var idAttribute = node.getAttribute("id");
  23521. if (idAttribute) {
  23522. var idElement = document.createElement("span");
  23523. parentElement.appendChild(idElement);
  23524.  
  23525. var part = "#" + idAttribute;
  23526. title += part;
  23527. idElement.appendChild(document.createTextNode(part));
  23528.  
  23529.  
  23530. nameElement.className = "extra";
  23531. }
  23532.  
  23533. var classAttribute = node.getAttribute("class");
  23534. if (classAttribute) {
  23535. var classes = classAttribute.split(/\s+/);
  23536. var foundClasses = {};
  23537.  
  23538. if (classes.length) {
  23539. var classesElement = document.createElement("span");
  23540. classesElement.className = "extra";
  23541. parentElement.appendChild(classesElement);
  23542.  
  23543. for (var i = 0; i < classes.length; ++i) {
  23544. var className = classes[i];
  23545. if (className && !(className in foundClasses)) {
  23546. var part = "." + className;
  23547. title += part;
  23548. classesElement.appendChild(document.createTextNode(part));
  23549. foundClasses[className] = true;
  23550. }
  23551. }
  23552. }
  23553. }
  23554. parentElement.title = title;
  23555. }
  23556.  
  23557.  
  23558. WebInspector.DOMPresentationUtils.createSpansForNodeTitle = function(container, nodeTitle)
  23559. {
  23560. var match = nodeTitle.match(/([^#.]+)(#[^.]+)?(\..*)?/);
  23561. container.createChild("span", "webkit-html-tag-name").textContent = match[1];
  23562. if (match[2])
  23563. container.createChild("span", "webkit-html-attribute-value").textContent = match[2];
  23564. if (match[3])
  23565. container.createChild("span", "webkit-html-attribute-name").textContent = match[3];
  23566. }
  23567.  
  23568. WebInspector.DOMPresentationUtils.linkifyNodeReference = function(node)
  23569. {
  23570. var link = document.createElement("span");
  23571. link.className = "node-link";
  23572. WebInspector.DOMPresentationUtils.decorateNodeLabel(node, link);
  23573.  
  23574. link.addEventListener("click", WebInspector.domAgent.inspectElement.bind(WebInspector.domAgent, node.id), false);
  23575. link.addEventListener("mouseover", WebInspector.domAgent.highlightDOMNode.bind(WebInspector.domAgent, node.id, "", undefined), false);
  23576. link.addEventListener("mouseout", WebInspector.domAgent.hideDOMNodeHighlight.bind(WebInspector.domAgent), false);
  23577.  
  23578. return link;
  23579. }
  23580.  
  23581. WebInspector.DOMPresentationUtils.linkifyNodeById = function(nodeId)
  23582. {
  23583. var node = WebInspector.domAgent.nodeForId(nodeId);
  23584. if (!node)
  23585. return document.createTextNode(WebInspector.UIString("<node>"));
  23586. return WebInspector.DOMPresentationUtils.linkifyNodeReference(node);
  23587. }
  23588.  
  23589.  
  23590. WebInspector.DOMPresentationUtils.buildImagePreviewContents = function(imageURL, showDimensions, userCallback, precomputedDimensions)
  23591. {
  23592. var resource = WebInspector.resourceTreeModel.resourceForURL(imageURL);
  23593. if (!resource) {
  23594. userCallback();
  23595. return;
  23596. }
  23597.  
  23598. var imageElement = document.createElement("img");
  23599. imageElement.addEventListener("load", buildContent, false);
  23600. imageElement.addEventListener("error", errorCallback, false);
  23601. resource.populateImageSource(imageElement);
  23602.  
  23603. function errorCallback()
  23604. {
  23605.  
  23606. userCallback();
  23607. }
  23608.  
  23609. function buildContent()
  23610. {
  23611. var container = document.createElement("table");
  23612. container.className = "image-preview-container";
  23613. var naturalWidth = precomputedDimensions ? precomputedDimensions.naturalWidth : imageElement.naturalWidth;
  23614. var naturalHeight = precomputedDimensions ? precomputedDimensions.naturalHeight : imageElement.naturalHeight;
  23615. var offsetWidth = precomputedDimensions ? precomputedDimensions.offsetWidth : naturalWidth;
  23616. var offsetHeight = precomputedDimensions ? precomputedDimensions.offsetHeight : naturalHeight;
  23617. var description;
  23618. if (showDimensions) {
  23619. if (offsetHeight === naturalHeight && offsetWidth === naturalWidth)
  23620. description = WebInspector.UIString("%d \xd7 %d pixels", offsetWidth, offsetHeight);
  23621. else
  23622. description = WebInspector.UIString("%d \xd7 %d pixels (Natural: %d \xd7 %d pixels)", offsetWidth, offsetHeight, naturalWidth, naturalHeight);
  23623. }
  23624.  
  23625. container.createChild("tr").createChild("td", "image-container").appendChild(imageElement);
  23626. if (description)
  23627. container.createChild("tr").createChild("td").createChild("span", "description").textContent = description;
  23628. userCallback(container);
  23629. }
  23630. }
  23631.  
  23632.  
  23633.  
  23634.  
  23635.  
  23636.  
  23637. WebInspector.SidebarSectionTreeElement = function(title, representedObject, hasChildren)
  23638. {
  23639. TreeElement.call(this, title.escapeHTML(), representedObject || {}, hasChildren);
  23640. this.expand();
  23641. }
  23642.  
  23643. WebInspector.SidebarSectionTreeElement.prototype = {
  23644. selectable: false,
  23645.  
  23646. collapse: function()
  23647. {
  23648.  
  23649. },
  23650.  
  23651. get smallChildren()
  23652. {
  23653. return this._smallChildren;
  23654. },
  23655.  
  23656. set smallChildren(x)
  23657. {
  23658. if (this._smallChildren === x)
  23659. return;
  23660.  
  23661. this._smallChildren = x;
  23662.  
  23663. if (this._smallChildren)
  23664. this._childrenListNode.addStyleClass("small");
  23665. else
  23666. this._childrenListNode.removeStyleClass("small");
  23667. },
  23668.  
  23669. onattach: function()
  23670. {
  23671. this._listItemNode.addStyleClass("sidebar-tree-section");
  23672. },
  23673.  
  23674. onreveal: function()
  23675. {
  23676. if (this.listItemElement)
  23677. this.listItemElement.scrollIntoViewIfNeeded(false);
  23678. },
  23679.  
  23680. __proto__: TreeElement.prototype
  23681. }
  23682.  
  23683.  
  23684. WebInspector.SidebarTreeElement = function(className, title, subtitle, representedObject, hasChildren)
  23685. {
  23686. TreeElement.call(this, "", representedObject, hasChildren);
  23687.  
  23688. if (hasChildren) {
  23689. this.disclosureButton = document.createElement("button");
  23690. this.disclosureButton.className = "disclosure-button";
  23691. }
  23692.  
  23693. if (!this.iconElement) {
  23694. this.iconElement = document.createElement("img");
  23695. this.iconElement.className = "icon";
  23696. }
  23697.  
  23698. this.statusElement = document.createElement("div");
  23699. this.statusElement.className = "status";
  23700.  
  23701. this.titlesElement = document.createElement("div");
  23702. this.titlesElement.className = "titles";
  23703.  
  23704. this.titleElement = document.createElement("span");
  23705. this.titleElement.className = "title";
  23706. this.titlesElement.appendChild(this.titleElement);
  23707.  
  23708. this.subtitleElement = document.createElement("span");
  23709. this.subtitleElement.className = "subtitle";
  23710. this.titlesElement.appendChild(this.subtitleElement);
  23711.  
  23712. this.className = className;
  23713. this.mainTitle = title;
  23714. this.subtitle = subtitle;
  23715. }
  23716.  
  23717. WebInspector.SidebarTreeElement.prototype = {
  23718. get small()
  23719. {
  23720. return this._small;
  23721. },
  23722.  
  23723. set small(x)
  23724. {
  23725. this._small = x;
  23726.  
  23727. if (this._listItemNode) {
  23728. if (this._small)
  23729. this._listItemNode.addStyleClass("small");
  23730. else
  23731. this._listItemNode.removeStyleClass("small");
  23732. }
  23733. },
  23734.  
  23735. get mainTitle()
  23736. {
  23737. return this._mainTitle;
  23738. },
  23739.  
  23740. set mainTitle(x)
  23741. {
  23742. this._mainTitle = x;
  23743. this.refreshTitles();
  23744. },
  23745.  
  23746. get subtitle()
  23747. {
  23748. return this._subtitle;
  23749. },
  23750.  
  23751. set subtitle(x)
  23752. {
  23753. this._subtitle = x;
  23754. this.refreshTitles();
  23755. },
  23756.  
  23757. get bubbleText()
  23758. {
  23759. return this._bubbleText;
  23760. },
  23761.  
  23762. set bubbleText(x)
  23763. {
  23764. if (!this.bubbleElement) {
  23765. this.bubbleElement = document.createElement("div");
  23766. this.bubbleElement.className = "bubble";
  23767. this.statusElement.appendChild(this.bubbleElement);
  23768. }
  23769.  
  23770. this._bubbleText = x;
  23771. this.bubbleElement.textContent = x;
  23772. },
  23773.  
  23774. set wait(x)
  23775. {
  23776. if (x)
  23777. this._listItemNode.addStyleClass("wait");
  23778. else
  23779. this._listItemNode.removeStyleClass("wait");
  23780. },
  23781.  
  23782. refreshTitles: function()
  23783. {
  23784. var mainTitle = this.mainTitle;
  23785. if (this.titleElement.textContent !== mainTitle)
  23786. this.titleElement.textContent = mainTitle;
  23787.  
  23788. var subtitle = this.subtitle;
  23789. if (subtitle) {
  23790. if (this.subtitleElement.textContent !== subtitle)
  23791. this.subtitleElement.textContent = subtitle;
  23792. this.titlesElement.removeStyleClass("no-subtitle");
  23793. } else {
  23794. this.subtitleElement.textContent = "";
  23795. this.titlesElement.addStyleClass("no-subtitle");
  23796. }
  23797. },
  23798.  
  23799. isEventWithinDisclosureTriangle: function(event)
  23800. {
  23801. return event.target === this.disclosureButton;
  23802. },
  23803.  
  23804. onattach: function()
  23805. {
  23806. this._listItemNode.addStyleClass("sidebar-tree-item");
  23807.  
  23808. if (this.className)
  23809. this._listItemNode.addStyleClass(this.className);
  23810.  
  23811. if (this.small)
  23812. this._listItemNode.addStyleClass("small");
  23813.  
  23814. if (this.hasChildren && this.disclosureButton)
  23815. this._listItemNode.appendChild(this.disclosureButton);
  23816.  
  23817. this._listItemNode.appendChild(this.iconElement);
  23818. this._listItemNode.appendChild(this.statusElement);
  23819. this._listItemNode.appendChild(this.titlesElement);
  23820. },
  23821.  
  23822. onreveal: function()
  23823. {
  23824. if (this._listItemNode)
  23825. this._listItemNode.scrollIntoViewIfNeeded(false);
  23826. },
  23827.  
  23828. __proto__: TreeElement.prototype
  23829. }
  23830.  
  23831.  
  23832.  
  23833.  
  23834.  
  23835.  
  23836. WebInspector.Section = function(title, subtitle)
  23837. {
  23838. this.element = document.createElement("div");
  23839. this.element.className = "section";
  23840. this.element._section = this;
  23841.  
  23842. this.headerElement = document.createElement("div");
  23843. this.headerElement.className = "header";
  23844.  
  23845. this.titleElement = document.createElement("div");
  23846. this.titleElement.className = "title";
  23847.  
  23848. this.subtitleElement = document.createElement("div");
  23849. this.subtitleElement.className = "subtitle";
  23850.  
  23851. this.headerElement.appendChild(this.subtitleElement);
  23852. this.headerElement.appendChild(this.titleElement);
  23853.  
  23854. this.headerElement.addEventListener("click", this.handleClick.bind(this), false);
  23855. this.element.appendChild(this.headerElement);
  23856.  
  23857. this.title = title;
  23858. this.subtitle = subtitle;
  23859. this._expanded = false;
  23860. }
  23861.  
  23862. WebInspector.Section.prototype = {
  23863. get title()
  23864. {
  23865. return this._title;
  23866. },
  23867.  
  23868. set title(x)
  23869. {
  23870. if (this._title === x)
  23871. return;
  23872. this._title = x;
  23873.  
  23874. if (x instanceof Node) {
  23875. this.titleElement.removeChildren();
  23876. this.titleElement.appendChild(x);
  23877. } else
  23878. this.titleElement.textContent = x;
  23879. },
  23880.  
  23881. get subtitle()
  23882. {
  23883. return this._subtitle;
  23884. },
  23885.  
  23886. set subtitle(x)
  23887. {
  23888. if (this._subtitle === x)
  23889. return;
  23890. this._subtitle = x;
  23891. this.subtitleElement.textContent = x;
  23892. },
  23893.  
  23894. get subtitleAsTextForTest()
  23895. {
  23896. var result = this.subtitleElement.textContent;
  23897. var child = this.subtitleElement.querySelector("[data-uncopyable]");
  23898. if (child) {
  23899. var linkData = child.getAttribute("data-uncopyable");
  23900. if (linkData)
  23901. result += linkData;
  23902. }
  23903. return result;
  23904. },
  23905.  
  23906. get expanded()
  23907. {
  23908. return this._expanded;
  23909. },
  23910.  
  23911. set expanded(x)
  23912. {
  23913. if (x)
  23914. this.expand();
  23915. else
  23916. this.collapse();
  23917. },
  23918.  
  23919. get populated()
  23920. {
  23921. return this._populated;
  23922. },
  23923.  
  23924. set populated(x)
  23925. {
  23926. this._populated = x;
  23927. if (!x && this._expanded) {
  23928. this.onpopulate();
  23929. this._populated = true;
  23930. }
  23931. },
  23932.  
  23933. onpopulate: function()
  23934. {
  23935.  
  23936. },
  23937.  
  23938. get firstSibling()
  23939. {
  23940. var parent = this.element.parentElement;
  23941. if (!parent)
  23942. return null;
  23943.  
  23944. var childElement = parent.firstChild;
  23945. while (childElement) {
  23946. if (childElement._section)
  23947. return childElement._section;
  23948. childElement = childElement.nextSibling;
  23949. }
  23950.  
  23951. return null;
  23952. },
  23953.  
  23954. get lastSibling()
  23955. {
  23956. var parent = this.element.parentElement;
  23957. if (!parent)
  23958. return null;
  23959.  
  23960. var childElement = parent.lastChild;
  23961. while (childElement) {
  23962. if (childElement._section)
  23963. return childElement._section;
  23964. childElement = childElement.previousSibling;
  23965. }
  23966.  
  23967. return null;
  23968. },
  23969.  
  23970. get nextSibling()
  23971. {
  23972. var curElement = this.element;
  23973. do {
  23974. curElement = curElement.nextSibling;
  23975. } while (curElement && !curElement._section);
  23976.  
  23977. return curElement ? curElement._section : null;
  23978. },
  23979.  
  23980. get previousSibling()
  23981. {
  23982. var curElement = this.element;
  23983. do {
  23984. curElement = curElement.previousSibling;
  23985. } while (curElement && !curElement._section);
  23986.  
  23987. return curElement ? curElement._section : null;
  23988. },
  23989.  
  23990. expand: function()
  23991. {
  23992. if (this._expanded)
  23993. return;
  23994. this._expanded = true;
  23995. this.element.addStyleClass("expanded");
  23996.  
  23997. if (!this._populated) {
  23998. this.onpopulate();
  23999. this._populated = true;
  24000. }
  24001. },
  24002.  
  24003. collapse: function()
  24004. {
  24005. if (!this._expanded)
  24006. return;
  24007. this._expanded = false;
  24008. this.element.removeStyleClass("expanded");
  24009. },
  24010.  
  24011. toggleExpanded: function()
  24012. {
  24013. this.expanded = !this.expanded;
  24014. },
  24015.  
  24016. handleClick: function(event)
  24017. {
  24018. this.toggleExpanded();
  24019. event.consume();
  24020. }
  24021. }
  24022.  
  24023.  
  24024.  
  24025.  
  24026.  
  24027.  
  24028. WebInspector.PropertiesSection = function(title, subtitle)
  24029. {
  24030. WebInspector.Section.call(this, title, subtitle);
  24031.  
  24032. this.headerElement.addStyleClass("monospace");
  24033. this.propertiesElement = document.createElement("ol");
  24034. this.propertiesElement.className = "properties properties-tree monospace";
  24035. this.propertiesTreeOutline = new TreeOutline(this.propertiesElement, true);
  24036. this.propertiesTreeOutline.setFocusable(false);
  24037. this.propertiesTreeOutline.section = this;
  24038.  
  24039. this.element.appendChild(this.propertiesElement);
  24040. }
  24041.  
  24042. WebInspector.PropertiesSection.prototype = {
  24043. __proto__: WebInspector.Section.prototype
  24044. }
  24045.  
  24046.  
  24047.  
  24048.  
  24049.  
  24050.  
  24051. WebInspector.RemoteObject = function(objectId, type, subtype, value, description, preview)
  24052. {
  24053. this._type = type;
  24054. this._subtype = subtype;
  24055. if (objectId) {
  24056.  
  24057. this._objectId = objectId;
  24058. this._description = description;
  24059. this._hasChildren = true;
  24060. this._preview = preview;
  24061. } else {
  24062.  
  24063. console.assert(type !== "object" || value === null);
  24064. this._description = description || (value + "");
  24065. this._hasChildren = false;
  24066. this.value = value;
  24067. }
  24068. }
  24069.  
  24070.  
  24071. WebInspector.RemoteObject.fromPrimitiveValue = function(value)
  24072. {
  24073. return new WebInspector.RemoteObject(undefined, typeof value, undefined, value);
  24074. }
  24075.  
  24076.  
  24077. WebInspector.RemoteObject.fromLocalObject = function(value)
  24078. {
  24079. return new WebInspector.LocalJSONObject(value);
  24080. }
  24081.  
  24082.  
  24083. WebInspector.RemoteObject.resolveNode = function(node, objectGroup, callback)
  24084. {
  24085.  
  24086. function mycallback(error, object)
  24087. {
  24088. if (!callback)
  24089. return;
  24090.  
  24091. if (error || !object)
  24092. callback(null);
  24093. else
  24094. callback(WebInspector.RemoteObject.fromPayload(object));
  24095. }
  24096. DOMAgent.resolveNode(node.id, objectGroup, mycallback);
  24097. }
  24098.  
  24099.  
  24100. WebInspector.RemoteObject.fromPayload = function(payload)
  24101. {
  24102. console.assert(typeof payload === "object", "Remote object payload should only be an object");
  24103.  
  24104. return new WebInspector.RemoteObject(payload.objectId, payload.type, payload.subtype, payload.value, payload.description, payload.preview);
  24105. }
  24106.  
  24107.  
  24108. WebInspector.RemoteObject.type = function(remoteObject)
  24109. {
  24110. if (remoteObject === null)
  24111. return "null";
  24112.  
  24113. var type = typeof remoteObject;
  24114. if (type !== "object" && type !== "function")
  24115. return type;
  24116.  
  24117. return remoteObject.type;
  24118. }
  24119.  
  24120. WebInspector.RemoteObject.prototype = {
  24121.  
  24122. get objectId()
  24123. {
  24124. return this._objectId;
  24125. },
  24126.  
  24127.  
  24128. get type()
  24129. {
  24130. return this._type;
  24131. },
  24132.  
  24133.  
  24134. get subtype()
  24135. {
  24136. return this._subtype;
  24137. },
  24138.  
  24139.  
  24140. get description()
  24141. {
  24142. return this._description;
  24143. },
  24144.  
  24145.  
  24146. get hasChildren()
  24147. {
  24148. return this._hasChildren;
  24149. },
  24150.  
  24151.  
  24152. get preview()
  24153. {
  24154. return this._preview;
  24155. },
  24156.  
  24157.  
  24158. getOwnProperties: function(callback)
  24159. {
  24160. this._getProperties(true, callback);
  24161. },
  24162.  
  24163.  
  24164. getAllProperties: function(callback)
  24165. {
  24166. this._getProperties(false, callback);
  24167. },
  24168.  
  24169.  
  24170. _getProperties: function(ownProperties, callback)
  24171. {
  24172. if (!this._objectId) {
  24173. callback([]);
  24174. return;
  24175. }
  24176.  
  24177.  
  24178. function remoteObjectBinder(error, properties, internalProperties)
  24179. {
  24180. if (error) {
  24181. callback(null);
  24182. return;
  24183. }
  24184. var result = [];
  24185. for (var i = 0; properties && i < properties.length; ++i) {
  24186. var property = properties[i];
  24187. if (property.get || property.set) {
  24188. if (property.get)
  24189. result.push(new WebInspector.RemoteObjectProperty("get " + property.name, WebInspector.RemoteObject.fromPayload(property.get), property));
  24190. if (property.set)
  24191. result.push(new WebInspector.RemoteObjectProperty("set " + property.name, WebInspector.RemoteObject.fromPayload(property.set), property));
  24192. } else
  24193. result.push(new WebInspector.RemoteObjectProperty(property.name, WebInspector.RemoteObject.fromPayload(property.value), property));
  24194. }
  24195. var internalPropertiesResult;
  24196. if (internalProperties) {
  24197. internalPropertiesResult = [];
  24198. for (var i = 0; i < internalProperties.length; i++) {
  24199. var property = internalProperties[i];
  24200. internalPropertiesResult.push(new WebInspector.RemoteObjectProperty(property.name, WebInspector.RemoteObject.fromPayload(property.value)));
  24201. }
  24202. }
  24203. callback(result, internalPropertiesResult);
  24204. }
  24205. RuntimeAgent.getProperties(this._objectId, ownProperties, remoteObjectBinder);
  24206. },
  24207.  
  24208.  
  24209. setPropertyValue: function(name, value, callback)
  24210. {
  24211. if (!this._objectId) {
  24212. callback("Can't set a property of non-object.");
  24213. return;
  24214. }
  24215.  
  24216. RuntimeAgent.evaluate.invoke({expression:value, doNotPauseOnExceptionsAndMuteConsole:true}, evaluatedCallback.bind(this));
  24217.  
  24218.  
  24219. function evaluatedCallback(error, result, wasThrown)
  24220. {
  24221. if (error || wasThrown) {
  24222. callback(error || result.description);
  24223. return;
  24224. }
  24225.  
  24226. var setPropertyValueFunction = "function(a, b) { this[a] = b; }";
  24227.  
  24228.  
  24229. if (result.type === "number" && typeof result.value !== "number")
  24230. setPropertyValueFunction = "function(a) { this[a] = " + result.description + "; }";
  24231.  
  24232. delete result.description; 
  24233. RuntimeAgent.callFunctionOn(this._objectId, setPropertyValueFunction, [{ value:name }, result], true, undefined, undefined, propertySetCallback.bind(this));
  24234. if (result._objectId)
  24235. RuntimeAgent.releaseObject(result._objectId);
  24236. }
  24237.  
  24238.  
  24239. function propertySetCallback(error, result, wasThrown)
  24240. {
  24241. if (error || wasThrown) {
  24242. callback(error || result.description);
  24243. return;
  24244. }
  24245. callback();
  24246. }
  24247. },
  24248.  
  24249.  
  24250. pushNodeToFrontend: function(callback)
  24251. {
  24252. if (this._objectId)
  24253. WebInspector.domAgent.pushNodeToFrontend(this._objectId, callback);
  24254. else
  24255. callback(0);
  24256. },
  24257.  
  24258. highlightAsDOMNode: function()
  24259. {
  24260. WebInspector.domAgent.highlightDOMNode(undefined, undefined, this._objectId);
  24261. },
  24262.  
  24263. hideDOMNodeHighlight: function()
  24264. {
  24265. WebInspector.domAgent.hideDOMNodeHighlight();
  24266. },
  24267.  
  24268.  
  24269. callFunction: function(functionDeclaration, args, callback)
  24270. {
  24271.  
  24272. function mycallback(error, result, wasThrown)
  24273. {
  24274. if (!callback)
  24275. return;
  24276.  
  24277. callback((error || wasThrown) ? null : WebInspector.RemoteObject.fromPayload(result));
  24278. }
  24279.  
  24280. RuntimeAgent.callFunctionOn(this._objectId, functionDeclaration.toString(), args, true, undefined, undefined, mycallback);
  24281. },
  24282.  
  24283.  
  24284. callFunctionJSON: function(functionDeclaration, args, callback)
  24285. {
  24286.  
  24287. function mycallback(error, result, wasThrown)
  24288. {
  24289. callback((error || wasThrown) ? null : result.value);
  24290. }
  24291.  
  24292. RuntimeAgent.callFunctionOn(this._objectId, functionDeclaration.toString(), args, true, true, false, mycallback);
  24293. },
  24294.  
  24295. release: function()
  24296. {
  24297. if (!this._objectId)
  24298. return;
  24299. RuntimeAgent.releaseObject(this._objectId);
  24300. },
  24301.  
  24302.  
  24303. arrayLength: function()
  24304. {
  24305. if (this.subtype !== "array")
  24306. return 0;
  24307.  
  24308. var matches = this._description.match(/\[([0-9]+)\]/);
  24309. if (!matches)
  24310. return 0;
  24311. return parseInt(matches[1], 10);
  24312. }
  24313. }
  24314.  
  24315.  
  24316. WebInspector.RemoteObjectProperty = function(name, value, descriptor)
  24317. {
  24318. this.name = name;
  24319. this.value = value;
  24320. this.enumerable = descriptor ? !!descriptor.enumerable : true;
  24321. this.writable = descriptor ? !!descriptor.writable : true;
  24322. if (descriptor && descriptor.wasThrown)
  24323. this.wasThrown = true;
  24324. }
  24325.  
  24326.  
  24327. WebInspector.RemoteObjectProperty.fromPrimitiveValue = function(name, value)
  24328. {
  24329. return new WebInspector.RemoteObjectProperty(name, WebInspector.RemoteObject.fromPrimitiveValue(value));
  24330. }
  24331.  
  24332.  
  24333. WebInspector.RemoteObjectProperty.fromScopeValue = function(name, value)
  24334. {
  24335. var result = new WebInspector.RemoteObjectProperty(name, value);
  24336. result.writable = false;
  24337. return result;
  24338. }
  24339.  
  24340.  
  24341.  
  24342.  
  24343.  
  24344.  
  24345.  
  24346.  
  24347. WebInspector.LocalJSONObject = function(value)
  24348. {
  24349. this._value = value;
  24350. }
  24351.  
  24352. WebInspector.LocalJSONObject.prototype = {
  24353.  
  24354. get description()
  24355. {
  24356. if (this._cachedDescription)
  24357. return this._cachedDescription;
  24358.  
  24359. if (this.type === "object") {
  24360. switch (this.subtype) {
  24361. case "array":
  24362. function formatArrayItem(property)
  24363. {
  24364. return property.value.description;
  24365. }
  24366. this._cachedDescription = this._concatenate("[", "]", formatArrayItem);
  24367. break;
  24368. case "date":
  24369. this._cachedDescription = "" + this._value;
  24370. break;
  24371. case "null":
  24372. this._cachedDescription = "null";
  24373. break;
  24374. default:
  24375. function formatObjectItem(property)
  24376. {
  24377. return property.name + ":" + property.value.description;
  24378. }
  24379. this._cachedDescription = this._concatenate("{", "}", formatObjectItem);
  24380. }
  24381. } else
  24382. this._cachedDescription = String(this._value);
  24383.  
  24384. return this._cachedDescription;
  24385. },
  24386.  
  24387.  
  24388. _concatenate: function(prefix, suffix, formatProperty)
  24389. {
  24390. const previewChars = 100;
  24391.  
  24392. var buffer = prefix;
  24393. var children = this._children();
  24394. for (var i = 0; i < children.length; ++i) {
  24395. var itemDescription = formatProperty(children[i]);
  24396. if (buffer.length + itemDescription.length > previewChars) {
  24397. buffer += ",\u2026";
  24398. break;
  24399. }
  24400. if (i)
  24401. buffer += ", ";
  24402. buffer += itemDescription;
  24403. }
  24404. buffer += suffix;
  24405. return buffer;
  24406. },
  24407.  
  24408.  
  24409. get type()
  24410. {
  24411. return typeof this._value;
  24412. },
  24413.  
  24414.  
  24415. get subtype()
  24416. {
  24417. if (this._value === null)
  24418. return "null";
  24419.  
  24420. if (this._value instanceof Array)
  24421. return "array";
  24422.  
  24423. if (this._value instanceof Date)
  24424. return "date";
  24425.  
  24426. return undefined;
  24427. },
  24428.  
  24429.  
  24430. get hasChildren()
  24431. {
  24432. return typeof this._value === "object" && this._value !== null && !!Object.keys(this._value).length;
  24433. },
  24434.  
  24435.  
  24436. getOwnProperties: function(callback)
  24437. {
  24438. callback(this._children());
  24439. },
  24440.  
  24441.  
  24442. getAllProperties: function(callback)
  24443. {
  24444. callback(this._children());
  24445. },
  24446.  
  24447.  
  24448. _children: function()
  24449. {
  24450. if (!this.hasChildren)
  24451. return [];
  24452.  
  24453. function buildProperty(propName)
  24454. {
  24455. return new WebInspector.RemoteObjectProperty(propName, new WebInspector.LocalJSONObject(this._value[propName]));
  24456. }
  24457. if (!this._cachedChildren)
  24458. this._cachedChildren = Object.keys(this._value || {}).map(buildProperty.bind(this));
  24459. return this._cachedChildren;
  24460. },
  24461.  
  24462.  
  24463. isError: function()
  24464. {
  24465. return false;
  24466. },
  24467.  
  24468.  
  24469. arrayLength: function()
  24470. {
  24471. return this._value instanceof Array ? this._value.length : 0;
  24472. }
  24473. }
  24474.  
  24475.  
  24476.  
  24477.  
  24478.  
  24479.  
  24480. WebInspector.ObjectPropertiesSection = function(object, title, subtitle, emptyPlaceholder, ignoreHasOwnProperty, extraProperties, treeElementConstructor)
  24481. {
  24482. this.emptyPlaceholder = (emptyPlaceholder || WebInspector.UIString("No Properties"));
  24483. this.object = object;
  24484. this.ignoreHasOwnProperty = ignoreHasOwnProperty;
  24485. this.extraProperties = extraProperties;
  24486. this.treeElementConstructor = treeElementConstructor || WebInspector.ObjectPropertyTreeElement;
  24487. this.editable = true;
  24488. this.skipProto = false;
  24489.  
  24490. WebInspector.PropertiesSection.call(this, title || "", subtitle);
  24491. }
  24492.  
  24493. WebInspector.ObjectPropertiesSection._arrayLoadThreshold = 100;
  24494.  
  24495. WebInspector.ObjectPropertiesSection.prototype = {
  24496. enableContextMenu: function()
  24497. {
  24498. this.element.addEventListener("contextmenu", this._contextMenuEventFired.bind(this), false);
  24499. },
  24500.  
  24501. _contextMenuEventFired: function(event)
  24502. {
  24503. var contextMenu = new WebInspector.ContextMenu(event);
  24504. contextMenu.appendApplicableItems(this.object);
  24505. contextMenu.show();
  24506. },
  24507.  
  24508. onpopulate: function()
  24509. {
  24510. this.update();
  24511. },
  24512.  
  24513. update: function()
  24514. {
  24515. if (this.object.arrayLength() > WebInspector.ObjectPropertiesSection._arrayLoadThreshold) {
  24516. this.propertiesTreeOutline.removeChildren();
  24517. WebInspector.ArrayGroupingTreeElement._populateArray(this.propertiesTreeOutline, this.object, 0, this.object.arrayLength() - 1);
  24518. return;
  24519. }
  24520.  
  24521.  
  24522. function callback(properties, internalProperties)
  24523. {
  24524. if (!properties)
  24525. return;
  24526. this.updateProperties(properties);
  24527. }
  24528.  
  24529. if (this.ignoreHasOwnProperty)
  24530. this.object.getAllProperties(callback.bind(this));
  24531. else
  24532. this.object.getOwnProperties(callback.bind(this));
  24533. },
  24534.  
  24535. updateProperties: function(properties, rootTreeElementConstructor, rootPropertyComparer)
  24536. {
  24537. if (!rootTreeElementConstructor)
  24538. rootTreeElementConstructor = this.treeElementConstructor;
  24539.  
  24540. if (!rootPropertyComparer)
  24541. rootPropertyComparer = WebInspector.ObjectPropertiesSection.CompareProperties;
  24542.  
  24543. if (this.extraProperties)
  24544. for (var i = 0; i < this.extraProperties.length; ++i)
  24545. properties.push(this.extraProperties[i]);
  24546.  
  24547. properties.sort(rootPropertyComparer);
  24548.  
  24549. this.propertiesTreeOutline.removeChildren();
  24550.  
  24551. for (var i = 0; i < properties.length; ++i) {
  24552. if (this.skipProto && properties[i].name === "__proto__")
  24553. continue;
  24554. properties[i].parentObject = this.object;
  24555. }
  24556.  
  24557. this.propertiesForTest = properties;
  24558.  
  24559. for (var i = 0; i < properties.length; ++i)
  24560. this.propertiesTreeOutline.appendChild(new rootTreeElementConstructor(properties[i]));
  24561.  
  24562. if (!this.propertiesTreeOutline.children.length) {
  24563. var title = document.createElement("div");
  24564. title.className = "info";
  24565. title.textContent = this.emptyPlaceholder;
  24566. var infoElement = new TreeElement(title, null, false);
  24567. this.propertiesTreeOutline.appendChild(infoElement);
  24568. }
  24569. },
  24570.  
  24571. __proto__: WebInspector.PropertiesSection.prototype
  24572. }
  24573.  
  24574. WebInspector.ObjectPropertiesSection.CompareProperties = function(propertyA, propertyB)
  24575. {
  24576. var a = propertyA.name;
  24577. var b = propertyB.name;
  24578. if (a === "__proto__")
  24579. return 1;
  24580. if (b === "__proto__")
  24581. return -1;
  24582.  
  24583.  
  24584.  
  24585.  
  24586.  
  24587. var diff = 0;
  24588. var chunk = /^\d+|^\D+/;
  24589. var chunka, chunkb, anum, bnum;
  24590. while (diff === 0) {
  24591. if (!a && b)
  24592. return -1;
  24593. if (!b && a)
  24594. return 1;
  24595. chunka = a.match(chunk)[0];
  24596. chunkb = b.match(chunk)[0];
  24597. anum = !isNaN(chunka);
  24598. bnum = !isNaN(chunkb);
  24599. if (anum && !bnum)
  24600. return -1;
  24601. if (bnum && !anum)
  24602. return 1;
  24603. if (anum && bnum) {
  24604. diff = chunka - chunkb;
  24605. if (diff === 0 && chunka.length !== chunkb.length) {
  24606. if (!+chunka && !+chunkb) 
  24607. return chunka.length - chunkb.length;
  24608. else
  24609. return chunkb.length - chunka.length;
  24610. }
  24611. } else if (chunka !== chunkb)
  24612. return (chunka < chunkb) ? -1 : 1;
  24613. a = a.substring(chunka.length);
  24614. b = b.substring(chunkb.length);
  24615. }
  24616. return diff;
  24617. }
  24618.  
  24619.  
  24620. WebInspector.ObjectPropertyTreeElement = function(property)
  24621. {
  24622. this.property = property;
  24623.  
  24624.  
  24625. TreeElement.call(this, "", null, false);
  24626. this.toggleOnClick = true;
  24627. this.selectable = false;
  24628. }
  24629.  
  24630. WebInspector.ObjectPropertyTreeElement.prototype = {
  24631. onpopulate: function()
  24632. {
  24633. return WebInspector.ObjectPropertyTreeElement.populate(this, this.property.value);
  24634. },
  24635.  
  24636. ondblclick: function(event)
  24637. {
  24638. if (this.property.writable)
  24639. this.startEditing(event);
  24640. },
  24641.  
  24642. onattach: function()
  24643. {
  24644. this.update();
  24645. },
  24646.  
  24647. update: function()
  24648. {
  24649. this.nameElement = document.createElement("span");
  24650. this.nameElement.className = "name";
  24651. this.nameElement.textContent = this.property.name;
  24652. if (!this.property.enumerable)
  24653. this.nameElement.addStyleClass("dimmed");
  24654.  
  24655. var separatorElement = document.createElement("span");
  24656. separatorElement.className = "separator";
  24657. separatorElement.textContent = ": ";
  24658.  
  24659. this.valueElement = document.createElement("span");
  24660. this.valueElement.className = "value";
  24661.  
  24662. var description = this.property.value.description;
  24663.  
  24664. if (this.property.wasThrown)
  24665. this.valueElement.textContent = "[Exception: " + description + "]";
  24666. else if (this.property.value.type === "string" && typeof description === "string") {
  24667. this.valueElement.textContent = "\"" + description.replace(/\n/g, "\u21B5") + "\"";
  24668. this.valueElement._originalTextContent = "\"" + description + "\"";
  24669. } else if (this.property.value.type === "function" && typeof description === "string") {
  24670. this.valueElement.textContent = /.*/.exec(description)[0].replace(/ +$/g, "");
  24671. this.valueElement._originalTextContent = description;
  24672. } else if (this.property.value.type !== "object" || this.property.value.subtype !== "node") 
  24673. this.valueElement.textContent = description;
  24674.  
  24675. if (this.property.wasThrown)
  24676. this.valueElement.addStyleClass("error");
  24677. if (this.property.value.subtype)
  24678. this.valueElement.addStyleClass("console-formatted-" + this.property.value.subtype);
  24679. else if (this.property.value.type)
  24680. this.valueElement.addStyleClass("console-formatted-" + this.property.value.type);
  24681.  
  24682. this.valueElement.addEventListener("contextmenu", this._contextMenuFired.bind(this, this.property.value), false);
  24683. if (this.property.value.type === "object" && this.property.value.subtype === "node" && this.property.value.description) {
  24684. WebInspector.DOMPresentationUtils.createSpansForNodeTitle(this.valueElement, this.property.value.description);
  24685. this.valueElement.addEventListener("mousemove", this._mouseMove.bind(this, this.property.value), false);
  24686. this.valueElement.addEventListener("mouseout", this._mouseOut.bind(this, this.property.value), false);
  24687. } else
  24688. this.valueElement.title = description || "";
  24689.  
  24690. this.listItemElement.removeChildren();
  24691.  
  24692. this.listItemElement.appendChild(this.nameElement);
  24693. this.listItemElement.appendChild(separatorElement);
  24694. this.listItemElement.appendChild(this.valueElement);
  24695. this.hasChildren = this.property.value.hasChildren && !this.property.wasThrown;
  24696. },
  24697.  
  24698. _contextMenuFired: function(value, event)
  24699. {
  24700. var contextMenu = new WebInspector.ContextMenu(event);
  24701. this.populateContextMenu(contextMenu);
  24702. contextMenu.appendApplicableItems(value);
  24703. contextMenu.show();
  24704. },
  24705.  
  24706.  
  24707. populateContextMenu: function(contextMenu)
  24708. {
  24709. },
  24710.  
  24711. _mouseMove: function(event)
  24712. {
  24713. this.property.value.highlightAsDOMNode();
  24714. },
  24715.  
  24716. _mouseOut: function(event)
  24717. {
  24718. this.property.value.hideDOMNodeHighlight();
  24719. },
  24720.  
  24721. updateSiblings: function()
  24722. {
  24723. if (this.parent.root)
  24724. this.treeOutline.section.update();
  24725. else
  24726. this.parent.shouldRefreshChildren = true;
  24727. },
  24728.  
  24729. renderPromptAsBlock: function()
  24730. {
  24731. return false;
  24732. },
  24733.  
  24734.  
  24735. elementAndValueToEdit: function(event)
  24736. {
  24737. return [this.valueElement, (typeof this.valueElement._originalTextContent === "string") ? this.valueElement._originalTextContent : undefined];
  24738. },
  24739.  
  24740. startEditing: function(event)
  24741. {
  24742. var elementAndValueToEdit = this.elementAndValueToEdit(event);
  24743. var elementToEdit = elementAndValueToEdit[0];
  24744. var valueToEdit = elementAndValueToEdit[1];
  24745.  
  24746. if (WebInspector.isBeingEdited(elementToEdit) || !this.treeOutline.section.editable || this._readOnly)
  24747. return;
  24748.  
  24749.  
  24750. if (typeof valueToEdit !== "undefined")
  24751. elementToEdit.textContent = valueToEdit;
  24752.  
  24753. var context = { expanded: this.expanded, elementToEdit: elementToEdit, previousContent: elementToEdit.textContent };
  24754.  
  24755.  
  24756. this.hasChildren = false;
  24757.  
  24758. this.listItemElement.addStyleClass("editing-sub-part");
  24759.  
  24760. this._prompt = new WebInspector.ObjectPropertyPrompt(this.editingCommitted.bind(this, null, elementToEdit.textContent, context.previousContent, context), this.editingCancelled.bind(this, null, context), this.renderPromptAsBlock());
  24761.  
  24762. function blurListener()
  24763. {
  24764. this.editingCommitted(null, elementToEdit.textContent, context.previousContent, context);
  24765. }
  24766.  
  24767. var proxyElement = this._prompt.attachAndStartEditing(elementToEdit, blurListener.bind(this));
  24768. window.getSelection().setBaseAndExtent(elementToEdit, 0, elementToEdit, 1);
  24769. proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this, context), false);
  24770. },
  24771.  
  24772.  
  24773. isEditing: function()
  24774. {
  24775. return !!this._prompt;
  24776. },
  24777.  
  24778. editingEnded: function(context)
  24779. {
  24780. this._prompt.detach();
  24781. delete this._prompt;
  24782.  
  24783. this.listItemElement.scrollLeft = 0;
  24784. this.listItemElement.removeStyleClass("editing-sub-part");
  24785. if (context.expanded)
  24786. this.expand();
  24787. },
  24788.  
  24789. editingCancelled: function(element, context)
  24790. {
  24791. this.editingEnded(context);
  24792. this.update();
  24793. },
  24794.  
  24795. editingCommitted: function(element, userInput, previousContent, context)
  24796. {
  24797. if (userInput === previousContent)
  24798. return this.editingCancelled(element, context); 
  24799.  
  24800. this.editingEnded(context);
  24801. this.applyExpression(userInput, true);
  24802. },
  24803.  
  24804. _promptKeyDown: function(context, event)
  24805. {
  24806. if (isEnterKey(event)) {
  24807. event.consume(true);
  24808. return this.editingCommitted(null, context.elementToEdit.textContent, context.previousContent, context);
  24809. }
  24810. if (event.keyIdentifier === "U+001B") { 
  24811. event.consume();
  24812. return this.editingCancelled(null, context);
  24813. }
  24814. },
  24815.  
  24816. applyExpression: function(expression, updateInterface)
  24817. {
  24818. expression = expression.trim();
  24819. var expressionLength = expression.length;
  24820. function callback(error)
  24821. {
  24822. if (!updateInterface)
  24823. return;
  24824.  
  24825. if (error)
  24826. this.update();
  24827.  
  24828. if (!expressionLength) {
  24829.  
  24830. this.parent.removeChild(this);
  24831. } else {
  24832.  
  24833. this.updateSiblings();
  24834. }
  24835. };
  24836. this.property.parentObject.setPropertyValue(this.property.name, expression.trim(), callback.bind(this));
  24837. },
  24838.  
  24839. propertyPath: function()
  24840. {
  24841. if ("_cachedPropertyPath" in this)
  24842. return this._cachedPropertyPath;
  24843.  
  24844. var current = this;
  24845. var result;
  24846.  
  24847. do {
  24848. if (current.property) {
  24849. if (result)
  24850. result = current.property.name + "." + result;
  24851. else
  24852. result = current.property.name;
  24853. }
  24854. current = current.parent;
  24855. } while (current && !current.root);
  24856.  
  24857. this._cachedPropertyPath = result;
  24858. return result;
  24859. },
  24860.  
  24861.  
  24862. __proto__: TreeElement.prototype
  24863. }
  24864.  
  24865.  
  24866. WebInspector.ObjectPropertyTreeElement.populate = function(treeElement, value) {
  24867. if (treeElement.children.length && !treeElement.shouldRefreshChildren)
  24868. return;
  24869.  
  24870. if (value.arrayLength() > WebInspector.ObjectPropertiesSection._arrayLoadThreshold) {
  24871. treeElement.removeChildren();
  24872. WebInspector.ArrayGroupingTreeElement._populateArray(treeElement, value, 0, value.arrayLength() - 1);
  24873. return;
  24874. }
  24875.  
  24876.  
  24877. function callback(properties, internalProperties)
  24878. {
  24879. treeElement.removeChildren();
  24880. if (!properties)
  24881. return;
  24882.  
  24883. properties.sort(WebInspector.ObjectPropertiesSection.CompareProperties);
  24884. for (var i = 0; i < properties.length; ++i) {
  24885. if (treeElement.treeOutline.section.skipProto && properties[i].name === "__proto__")
  24886. continue;
  24887. properties[i].parentObject = value;
  24888. treeElement.appendChild(new treeElement.treeOutline.section.treeElementConstructor(properties[i]));
  24889. }
  24890. if (value.type === "function") {
  24891.  
  24892.  
  24893.  
  24894. var hasTargetFunction = false;
  24895.  
  24896. if (internalProperties) {
  24897. for (var i = 0; i < internalProperties.length; i++) {
  24898. if (internalProperties[i].name == "[[TargetFunction]]") {
  24899. hasTargetFunction = true;
  24900. break;
  24901. }
  24902. }
  24903. }
  24904. if (!hasTargetFunction)
  24905. treeElement.appendChild(new WebInspector.FunctionScopeMainTreeElement(value));
  24906. }
  24907. if (internalProperties) {
  24908. for (var i = 0; i < internalProperties.length; i++) {
  24909. internalProperties[i].parentObject = value;
  24910. treeElement.appendChild(new treeElement.treeOutline.section.treeElementConstructor(internalProperties[i]));
  24911. }
  24912. }
  24913.  
  24914. value.getOwnProperties(callback);
  24915. }
  24916.  
  24917.  
  24918. WebInspector.FunctionScopeMainTreeElement = function(remoteObject)
  24919. {
  24920. TreeElement.call(this, "<function scope>", null, false);
  24921. this.toggleOnClick = true;
  24922. this.selectable = false;
  24923. this._remoteObject = remoteObject;
  24924. this.hasChildren = true;
  24925. }
  24926.  
  24927. WebInspector.FunctionScopeMainTreeElement.prototype = {
  24928. onpopulate: function()
  24929. {
  24930. if (this.children.length && !this.shouldRefreshChildren)
  24931. return;
  24932.  
  24933. function didGetDetails(error, response)
  24934. {
  24935. if (error) {
  24936. console.error(error);
  24937. return;
  24938. }
  24939. this.removeChildren();
  24940.  
  24941. var scopeChain = response.scopeChain;
  24942. if (!scopeChain)
  24943. return;
  24944. for (var i = 0; i < scopeChain.length; ++i) {
  24945. var scope = scopeChain[i];
  24946. var title = null;
  24947. var isTrueObject;
  24948.  
  24949. switch (scope.type) {
  24950. case "local":
  24951.  
  24952. title = WebInspector.UIString("Local");
  24953. isTrueObject = false;
  24954. break;
  24955. case "closure":
  24956. title = WebInspector.UIString("Closure");
  24957. isTrueObject = false;
  24958. break;
  24959. case "catch":
  24960. title = WebInspector.UIString("Catch");
  24961. isTrueObject = false;
  24962. break;
  24963. case "with":
  24964. title = WebInspector.UIString("With Block");
  24965. isTrueObject = true;
  24966. break;
  24967. case "global":
  24968. title = WebInspector.UIString("Global");
  24969. isTrueObject = true;
  24970. break;
  24971. }
  24972.  
  24973. var remoteObject = WebInspector.RemoteObject.fromPayload(scope.object);
  24974. if (isTrueObject) {
  24975. var property = WebInspector.RemoteObjectProperty.fromScopeValue(title, remoteObject);
  24976. property.parentObject = null;
  24977. this.appendChild(new this.treeOutline.section.treeElementConstructor(property));
  24978. } else {
  24979. var scopeTreeElement = new WebInspector.ScopeTreeElement(title, null, remoteObject);
  24980. this.appendChild(scopeTreeElement);
  24981. }
  24982. }
  24983.  
  24984. }
  24985. DebuggerAgent.getFunctionDetails(this._remoteObject.objectId, didGetDetails.bind(this));
  24986. },
  24987.  
  24988. __proto__: TreeElement.prototype
  24989. }
  24990.  
  24991.  
  24992. WebInspector.ScopeTreeElement = function(title, subtitle, remoteObject)
  24993. {
  24994.  
  24995. TreeElement.call(this, title, null, false);
  24996. this.toggleOnClick = true;
  24997. this.selectable = false;
  24998. this._remoteObject = remoteObject;
  24999. this.hasChildren = true;
  25000. }
  25001.  
  25002. WebInspector.ScopeTreeElement.prototype = {
  25003. onpopulate: function()
  25004. {
  25005. return WebInspector.ObjectPropertyTreeElement.populate(this, this._remoteObject);
  25006. },
  25007.  
  25008. __proto__: TreeElement.prototype
  25009. }
  25010.  
  25011.  
  25012. WebInspector.ArrayGroupingTreeElement = function(object, fromIndex, toIndex, propertyCount)
  25013. {
  25014. TreeElement.call(this, String.sprintf("[%d \u2026 %d]", fromIndex, toIndex), undefined, true);
  25015. this._fromIndex = fromIndex;
  25016. this._toIndex = toIndex;
  25017. this._object = object;
  25018. this._readOnly = true;
  25019. this._propertyCount = propertyCount;
  25020. this._populated = false;
  25021. }
  25022.  
  25023. WebInspector.ArrayGroupingTreeElement._bucketThreshold = 100;
  25024.  
  25025.  
  25026. WebInspector.ArrayGroupingTreeElement._populateArray = function(treeElement, object, fromIndex, toIndex)
  25027. {
  25028. WebInspector.ArrayGroupingTreeElement._populateRanges(treeElement, object, fromIndex, toIndex, true);
  25029. }
  25030.  
  25031.  
  25032. WebInspector.ArrayGroupingTreeElement._populateRanges = function(treeElement, object, fromIndex, toIndex, topLevel)
  25033. {
  25034. object.callFunctionJSON(packRanges, [{value: fromIndex}, {value: toIndex}, {value: WebInspector.ArrayGroupingTreeElement._bucketThreshold}], callback.bind(this));
  25035.  
  25036.  
  25037. function packRanges(fromIndex, toIndex, bucketThreshold)
  25038. {
  25039. var count = 0;
  25040. for (var i = fromIndex; i <= toIndex; ++i) {
  25041. if (i in this)
  25042. ++count;
  25043. }
  25044.  
  25045. var bucketSize = count;
  25046. if (count <= bucketThreshold)
  25047. bucketSize = count;
  25048. else
  25049. bucketSize = Math.pow(bucketThreshold, Math.ceil(Math.log(count) / Math.log(bucketThreshold)) - 1);
  25050.  
  25051. var ranges = [];
  25052. count = 0;
  25053. var groupStart = -1;
  25054. var groupEnd = 0;
  25055. for (var i = fromIndex; i <= toIndex; ++i) {
  25056. if (!(i in this))
  25057. continue;
  25058.  
  25059. if (groupStart === -1)
  25060. groupStart = i;
  25061.  
  25062. groupEnd = i;
  25063. if (++count === bucketSize) {
  25064. ranges.push([groupStart, groupEnd, count]);
  25065. count = 0;
  25066. groupStart = -1;
  25067. }
  25068. }
  25069.  
  25070. if (count > 0)
  25071. ranges.push([groupStart, groupEnd, count]);
  25072. return ranges;
  25073. }
  25074.  
  25075. function callback(ranges)
  25076. {
  25077. if (ranges.length == 1)
  25078. WebInspector.ArrayGroupingTreeElement._populateAsFragment(treeElement, object, ranges[0][0], ranges[0][1]);
  25079. else {
  25080. for (var i = 0; i < ranges.length; ++i) {
  25081. var fromIndex = ranges[i][0];
  25082. var toIndex = ranges[i][1];
  25083. var count = ranges[i][2];
  25084. if (fromIndex == toIndex)
  25085. WebInspector.ArrayGroupingTreeElement._populateAsFragment(treeElement, object, fromIndex, toIndex);
  25086. else
  25087. treeElement.appendChild(new WebInspector.ArrayGroupingTreeElement(object, fromIndex, toIndex, count));
  25088. }
  25089. }
  25090. if (topLevel)
  25091. WebInspector.ArrayGroupingTreeElement._populateNonIndexProperties(treeElement, object);
  25092. }
  25093. }
  25094.  
  25095.  
  25096. WebInspector.ArrayGroupingTreeElement._populateAsFragment = function(treeElement, object, fromIndex, toIndex)
  25097. {
  25098. object.callFunction(buildArrayFragment, [{value: fromIndex}, {value: toIndex}], processArrayFragment.bind(this));
  25099.  
  25100.  
  25101. function buildArrayFragment(fromIndex, toIndex)
  25102. {
  25103. var result = Object.create(null);
  25104. for (var i = fromIndex; i <= toIndex; ++i) {
  25105. if (i in this)
  25106. result[i] = this[i];
  25107. }
  25108. return result;
  25109. }
  25110.  
  25111. function processArrayFragment(arrayFragment)
  25112. {
  25113. arrayFragment.getAllProperties(processProperties.bind(this));
  25114. }
  25115.  
  25116.  
  25117. function processProperties(properties, internalProperties)
  25118. {
  25119. if (!properties)
  25120. return;
  25121.  
  25122. properties.sort(WebInspector.ObjectPropertiesSection.CompareProperties);
  25123. for (var i = 0; i < properties.length; ++i) {
  25124. properties[i].parentObject = this._object;
  25125. var childTreeElement = new treeElement.treeOutline.section.treeElementConstructor(properties[i]);
  25126. childTreeElement._readOnly = true;
  25127. treeElement.appendChild(childTreeElement);
  25128. }
  25129. }
  25130. }
  25131.  
  25132.  
  25133. WebInspector.ArrayGroupingTreeElement._populateNonIndexProperties = function(treeElement, object)
  25134. {
  25135. object.callFunction(buildObjectFragment, undefined, processObjectFragment.bind(this));
  25136.  
  25137.  
  25138. function buildObjectFragment()
  25139. {
  25140. var result = Object.create(this.__proto__);
  25141. var names = Object.getOwnPropertyNames(this);
  25142. for (var i = 0; i < names.length; ++i) {
  25143. var name = names[i];
  25144. if (!isNaN(name))
  25145. continue;
  25146. var descriptor = Object.getOwnPropertyDescriptor(this, name);
  25147. if (descriptor)
  25148. Object.defineProperty(result, name, descriptor);
  25149. }
  25150. return result;
  25151. }
  25152.  
  25153. function processObjectFragment(arrayFragment)
  25154. {
  25155. arrayFragment.getOwnProperties(processProperties.bind(this));
  25156. }
  25157.  
  25158.  
  25159. function processProperties(properties, internalProperties)
  25160. {
  25161. if (!properties)
  25162. return;
  25163.  
  25164. properties.sort(WebInspector.ObjectPropertiesSection.CompareProperties);
  25165. for (var i = 0; i < properties.length; ++i) {
  25166. properties[i].parentObject = this._object;
  25167. var childTreeElement = new treeElement.treeOutline.section.treeElementConstructor(properties[i]);
  25168. childTreeElement._readOnly = true;
  25169. treeElement.appendChild(childTreeElement);
  25170. }
  25171. }
  25172. }
  25173.  
  25174. WebInspector.ArrayGroupingTreeElement.prototype = {
  25175. onpopulate: function()
  25176. {
  25177. if (this._populated)
  25178. return;
  25179.  
  25180. this._populated = true;
  25181.  
  25182. if (this._propertyCount >= WebInspector.ArrayGroupingTreeElement._bucketThreshold) {
  25183. WebInspector.ArrayGroupingTreeElement._populateRanges(this, this._object, this._fromIndex, this._toIndex, false);
  25184. return;
  25185. }
  25186. WebInspector.ArrayGroupingTreeElement._populateAsFragment(this, this._object, this._fromIndex, this._toIndex);
  25187. },
  25188.  
  25189. onattach: function()
  25190. {
  25191. this.listItemElement.addStyleClass("name");
  25192. },
  25193.  
  25194. __proto__: TreeElement.prototype
  25195. }
  25196.  
  25197.  
  25198. WebInspector.ObjectPropertyPrompt = function(commitHandler, cancelHandler, renderAsBlock)
  25199. {
  25200. WebInspector.TextPrompt.call(this, WebInspector.runtimeModel.completionsForTextPrompt.bind(WebInspector.runtimeModel));
  25201. this.setSuggestBoxEnabled("generic-suggest");
  25202. if (renderAsBlock)
  25203. this.renderAsBlock();
  25204. }
  25205.  
  25206. WebInspector.ObjectPropertyPrompt.prototype = {
  25207. __proto__: WebInspector.TextPrompt.prototype
  25208. }
  25209.  
  25210.  
  25211.  
  25212.  
  25213.  
  25214.  
  25215. WebInspector.ObjectPopoverHelper = function(panelElement, getAnchor, queryObject, onHide, disableOnClick)
  25216. {
  25217. WebInspector.PopoverHelper.call(this, panelElement, getAnchor, this._showObjectPopover.bind(this), this._onHideObjectPopover.bind(this), disableOnClick);
  25218. this._queryObject = queryObject;
  25219. this._onHideCallback = onHide;
  25220. this._popoverObjectGroup = "popover";
  25221. panelElement.addEventListener("scroll", this.hidePopover.bind(this), true);
  25222. };
  25223.  
  25224. WebInspector.ObjectPopoverHelper.prototype = {
  25225.  
  25226. _showObjectPopover: function(element, popover)
  25227. {
  25228.  
  25229. function showObjectPopover(result, wasThrown, anchorOverride)
  25230. {
  25231. if (popover.disposed)
  25232. return;
  25233. if (wasThrown) {
  25234. this.hidePopover();
  25235. return;
  25236. }
  25237.  
  25238. var anchorElement = anchorOverride || element;
  25239.  
  25240. var popoverContentElement = null;
  25241. if (result.type !== "object") {
  25242. popoverContentElement = document.createElement("span");
  25243. popoverContentElement.className = "monospace console-formatted-" + result.type;
  25244. popoverContentElement.style.whiteSpace = "pre";
  25245. popoverContentElement.textContent = result.description;
  25246. if (result.type === "function") {
  25247. function didGetDetails(error, response)
  25248. {
  25249. if (error) {
  25250. console.error(error);
  25251. return;
  25252. }
  25253. var container = document.createElement("div");
  25254. container.style.display = "inline-block";
  25255.  
  25256. var title = container.createChild("div", "function-popover-title source-code");
  25257. var functionName = title.createChild("span", "function-name");
  25258. functionName.textContent = response.name || response.inferredName || response.displayName || WebInspector.UIString("(anonymous function)");
  25259.  
  25260. this._linkifier = new WebInspector.Linkifier();
  25261. var rawLocation =   (response.location);
  25262. var link = this._linkifier.linkifyRawLocation(rawLocation, "function-location-link");
  25263. if (link)
  25264. title.appendChild(link);
  25265.  
  25266. container.appendChild(popoverContentElement);
  25267.  
  25268. popover.show(container, anchorElement);
  25269. }
  25270. DebuggerAgent.getFunctionDetails(result.objectId, didGetDetails.bind(this));
  25271. return;
  25272. }
  25273. if (result.type === "string")
  25274. popoverContentElement.textContent = "\"" + popoverContentElement.textContent + "\"";
  25275. popover.show(popoverContentElement, anchorElement);
  25276. } else {
  25277. popoverContentElement = document.createElement("div");
  25278.  
  25279. this._titleElement = document.createElement("div");
  25280. this._titleElement.className = "source-frame-popover-title monospace";
  25281. this._titleElement.textContent = result.description;
  25282. popoverContentElement.appendChild(this._titleElement);
  25283.  
  25284. var section = new WebInspector.ObjectPropertiesSection(result);
  25285.  
  25286. if (result.description.substr(0, 4) === "HTML") {
  25287. this._sectionUpdateProperties = section.updateProperties.bind(section);
  25288. section.updateProperties = this._updateHTMLId.bind(this);
  25289. }
  25290. section.expanded = true;
  25291. section.element.addStyleClass("source-frame-popover-tree");
  25292. section.headerElement.addStyleClass("hidden");
  25293. popoverContentElement.appendChild(section.element);
  25294.  
  25295. const popoverWidth = 300;
  25296. const popoverHeight = 250;
  25297. popover.show(popoverContentElement, anchorElement, popoverWidth, popoverHeight);
  25298. }
  25299. }
  25300. this._queryObject(element, showObjectPopover.bind(this), this._popoverObjectGroup);
  25301. },
  25302.  
  25303. _onHideObjectPopover: function()
  25304. {
  25305. if (this._linkifier) {
  25306. this._linkifier.reset();
  25307. delete this._linkifier;
  25308. }
  25309. if (this._onHideCallback)
  25310. this._onHideCallback();
  25311. RuntimeAgent.releaseObjectGroup(this._popoverObjectGroup);
  25312. },
  25313.  
  25314. _updateHTMLId: function(properties, rootTreeElementConstructor, rootPropertyComparer)
  25315. {
  25316. for (var i = 0; i < properties.length; ++i) {
  25317. if (properties[i].name === "id") {
  25318. if (properties[i].value.description)
  25319. this._titleElement.textContent += "#" + properties[i].value.description;
  25320. break;
  25321. }
  25322. }
  25323. this._sectionUpdateProperties(properties, rootTreeElementConstructor, rootPropertyComparer);
  25324. },
  25325.  
  25326. __proto__: WebInspector.PopoverHelper.prototype
  25327. }
  25328.  
  25329.  
  25330.  
  25331.  
  25332.  
  25333.  
  25334. WebInspector.NativeBreakpointsSidebarPane = function(title)
  25335. {
  25336. WebInspector.SidebarPane.call(this, title);
  25337.  
  25338. this.listElement = document.createElement("ol");
  25339. this.listElement.className = "breakpoint-list";
  25340.  
  25341. this.emptyElement = document.createElement("div");
  25342. this.emptyElement.className = "info";
  25343. this.emptyElement.textContent = WebInspector.UIString("No Breakpoints");
  25344.  
  25345. this.bodyElement.appendChild(this.emptyElement);
  25346. }
  25347.  
  25348. WebInspector.NativeBreakpointsSidebarPane.prototype = {
  25349. _addListElement: function(element, beforeElement)
  25350. {
  25351. if (beforeElement)
  25352. this.listElement.insertBefore(element, beforeElement);
  25353. else {
  25354. if (!this.listElement.firstChild) {
  25355. this.bodyElement.removeChild(this.emptyElement);
  25356. this.bodyElement.appendChild(this.listElement);
  25357. }
  25358. this.listElement.appendChild(element);
  25359. }
  25360. },
  25361.  
  25362. _removeListElement: function(element)
  25363. {
  25364. this.listElement.removeChild(element);
  25365. if (!this.listElement.firstChild) {
  25366. this.bodyElement.removeChild(this.listElement);
  25367. this.bodyElement.appendChild(this.emptyElement);
  25368. }
  25369. },
  25370.  
  25371. _reset: function()
  25372. {
  25373. this.listElement.removeChildren();
  25374. if (this.listElement.parentElement) {
  25375. this.bodyElement.removeChild(this.listElement);
  25376. this.bodyElement.appendChild(this.emptyElement);
  25377. }
  25378. },
  25379.  
  25380. __proto__: WebInspector.SidebarPane.prototype
  25381. }
  25382.  
  25383.  
  25384.  
  25385.  
  25386.  
  25387.  
  25388. WebInspector.DOMBreakpointsSidebarPane = function()
  25389. {
  25390. WebInspector.NativeBreakpointsSidebarPane.call(this, WebInspector.UIString("DOM Breakpoints"));
  25391.  
  25392. this._breakpointElements = {};
  25393.  
  25394. this._breakpointTypes = {
  25395. SubtreeModified: "subtree-modified",
  25396. AttributeModified: "attribute-modified",
  25397. NodeRemoved: "node-removed"
  25398. };
  25399. this._breakpointTypeLabels = {};
  25400. this._breakpointTypeLabels[this._breakpointTypes.SubtreeModified] = WebInspector.UIString("Subtree Modified");
  25401. this._breakpointTypeLabels[this._breakpointTypes.AttributeModified] = WebInspector.UIString("Attribute Modified");
  25402. this._breakpointTypeLabels[this._breakpointTypes.NodeRemoved] = WebInspector.UIString("Node Removed");
  25403.  
  25404. this._contextMenuLabels = {};
  25405. this._contextMenuLabels[this._breakpointTypes.SubtreeModified] = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Subtree modifications" : "Subtree Modifications");
  25406. this._contextMenuLabels[this._breakpointTypes.AttributeModified] = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Attributes modifications" : "Attributes Modifications");
  25407. this._contextMenuLabels[this._breakpointTypes.NodeRemoved] = WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Node removal" : "Node Removal");
  25408.  
  25409. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.InspectedURLChanged, this._inspectedURLChanged, this);
  25410. WebInspector.domAgent.addEventListener(WebInspector.DOMAgent.Events.NodeRemoved, this._nodeRemoved, this);
  25411. }
  25412.  
  25413. WebInspector.DOMBreakpointsSidebarPane.prototype = {
  25414. _inspectedURLChanged: function(event)
  25415. {
  25416. this._breakpointElements = {};
  25417. this._reset();
  25418. var url = event.data;
  25419. this._inspectedURL = url.removeURLFragment();
  25420. },
  25421.  
  25422. populateNodeContextMenu: function(node, contextMenu)
  25423. {
  25424. var nodeBreakpoints = {};
  25425. for (var id in this._breakpointElements) {
  25426. var element = this._breakpointElements[id];
  25427. if (element._node === node)
  25428. nodeBreakpoints[element._type] = true;
  25429. }
  25430.  
  25431. function toggleBreakpoint(type)
  25432. {
  25433. if (!nodeBreakpoints[type])
  25434. this._setBreakpoint(node, type, true);
  25435. else
  25436. this._removeBreakpoint(node, type);
  25437. this._saveBreakpoints();
  25438. }
  25439.  
  25440. var breakPointSubMenu = contextMenu.appendSubMenuItem(WebInspector.UIString("Break on..."));
  25441. for (var key in this._breakpointTypes) {
  25442. var type = this._breakpointTypes[key];
  25443. var label = this._contextMenuLabels[type];
  25444. breakPointSubMenu.appendCheckboxItem(label, toggleBreakpoint.bind(this, type), nodeBreakpoints[type]);
  25445. }
  25446. },
  25447.  
  25448. createBreakpointHitStatusMessage: function(auxData, callback)
  25449. {
  25450. if (auxData.type === this._breakpointTypes.SubtreeModified) {
  25451. var targetNodeObject = WebInspector.RemoteObject.fromPayload(auxData["targetNode"]);
  25452. function didPushNodeToFrontend(targetNodeId)
  25453. {
  25454. if (targetNodeId)
  25455. targetNodeObject.release();
  25456. this._doCreateBreakpointHitStatusMessage(auxData, targetNodeId, callback);
  25457. }
  25458. targetNodeObject.pushNodeToFrontend(didPushNodeToFrontend.bind(this));
  25459. } else
  25460. this._doCreateBreakpointHitStatusMessage(auxData, null, callback);
  25461. },
  25462.  
  25463. _doCreateBreakpointHitStatusMessage: function (auxData, targetNodeId, callback)
  25464. {
  25465. var message;
  25466. var typeLabel = this._breakpointTypeLabels[auxData.type];
  25467. var linkifiedNode = WebInspector.DOMPresentationUtils.linkifyNodeById(auxData.nodeId);
  25468. var substitutions = [typeLabel, linkifiedNode];
  25469. var targetNode = "";
  25470. if (targetNodeId)
  25471. targetNode = WebInspector.DOMPresentationUtils.linkifyNodeById(targetNodeId);
  25472.  
  25473. if (auxData.type === this._breakpointTypes.SubtreeModified) {
  25474. if (auxData.insertion) {
  25475. if (targetNodeId !== auxData.nodeId) {
  25476. message = "Paused on a \"%s\" breakpoint set on %s, because a new child was added to its descendant %s.";
  25477. substitutions.push(targetNode);
  25478. } else
  25479. message = "Paused on a \"%s\" breakpoint set on %s, because a new child was added to that node.";
  25480. } else {
  25481. message = "Paused on a \"%s\" breakpoint set on %s, because its descendant %s was removed.";
  25482. substitutions.push(targetNode);
  25483. }
  25484. } else
  25485. message = "Paused on a \"%s\" breakpoint set on %s.";
  25486.  
  25487. var element = document.createElement("span");
  25488. var formatters = {
  25489. s: function(substitution)
  25490. {
  25491. return substitution;
  25492. }
  25493. };
  25494. function append(a, b)
  25495. {
  25496. if (typeof b === "string")
  25497. b = document.createTextNode(b);
  25498. element.appendChild(b);
  25499. }
  25500. WebInspector.formatLocalized(message, substitutions, formatters, "", append);
  25501.  
  25502. callback(element);
  25503. },
  25504.  
  25505. _nodeRemoved: function(event)
  25506. {
  25507. var node = event.data.node;
  25508. this._removeBreakpointsForNode(event.data.node);
  25509. if (!node.children)
  25510. return;
  25511. for (var i = 0; i < node.children.length; ++i)
  25512. this._removeBreakpointsForNode(node.children[i]);
  25513. this._saveBreakpoints();
  25514. },
  25515.  
  25516. _removeBreakpointsForNode: function(node)
  25517. {
  25518. for (var id in this._breakpointElements) {
  25519. var element = this._breakpointElements[id];
  25520. if (element._node === node)
  25521. this._removeBreakpoint(element._node, element._type);
  25522. }
  25523. },
  25524.  
  25525. _setBreakpoint: function(node, type, enabled)
  25526. {
  25527. var breakpointId = this._createBreakpointId(node.id, type);
  25528. if (breakpointId in this._breakpointElements)
  25529. return;
  25530.  
  25531. var element = document.createElement("li");
  25532. element._node = node;
  25533. element._type = type;
  25534. element.addEventListener("contextmenu", this._contextMenu.bind(this, node, type), true);
  25535.  
  25536. var checkboxElement = document.createElement("input");
  25537. checkboxElement.className = "checkbox-elem";
  25538. checkboxElement.type = "checkbox";
  25539. checkboxElement.checked = enabled;
  25540. checkboxElement.addEventListener("click", this._checkboxClicked.bind(this, node, type), false);
  25541. element._checkboxElement = checkboxElement;
  25542. element.appendChild(checkboxElement);
  25543.  
  25544. var labelElement = document.createElement("span");
  25545. element.appendChild(labelElement);
  25546.  
  25547. var linkifiedNode = WebInspector.DOMPresentationUtils.linkifyNodeById(node.id);
  25548. linkifiedNode.addStyleClass("monospace");
  25549. labelElement.appendChild(linkifiedNode);
  25550.  
  25551. var description = document.createElement("div");
  25552. description.className = "source-text";
  25553. description.textContent = this._breakpointTypeLabels[type];
  25554. labelElement.appendChild(description);
  25555.  
  25556. var currentElement = this.listElement.firstChild;
  25557. while (currentElement) {
  25558. if (currentElement._type && currentElement._type < element._type)
  25559. break;
  25560. currentElement = currentElement.nextSibling;
  25561. }
  25562. this._addListElement(element, currentElement);
  25563. this._breakpointElements[breakpointId] = element;
  25564. if (enabled)
  25565. DOMDebuggerAgent.setDOMBreakpoint(node.id, type);
  25566. },
  25567.  
  25568. _removeAllBreakpoints: function()
  25569. {
  25570. for (var id in this._breakpointElements) {
  25571. var element = this._breakpointElements[id];
  25572. this._removeBreakpoint(element._node, element._type);
  25573. }
  25574. this._saveBreakpoints();
  25575. },
  25576.  
  25577. _removeBreakpoint: function(node, type)
  25578. {
  25579. var breakpointId = this._createBreakpointId(node.id, type);
  25580. var element = this._breakpointElements[breakpointId];
  25581. if (!element)
  25582. return;
  25583.  
  25584. this._removeListElement(element);
  25585. delete this._breakpointElements[breakpointId];
  25586. if (element._checkboxElement.checked)
  25587. DOMDebuggerAgent.removeDOMBreakpoint(node.id, type);
  25588. },
  25589.  
  25590. _contextMenu: function(node, type, event)
  25591. {
  25592. var contextMenu = new WebInspector.ContextMenu(event);
  25593. function removeBreakpoint()
  25594. {
  25595. this._removeBreakpoint(node, type);
  25596. this._saveBreakpoints();
  25597. }
  25598. contextMenu.appendItem(WebInspector.UIString("Remove Breakpoint"), removeBreakpoint.bind(this));
  25599. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Remove all DOM breakpoints" : "Remove All DOM Breakpoints"), this._removeAllBreakpoints.bind(this));
  25600. contextMenu.show();
  25601. },
  25602.  
  25603. _checkboxClicked: function(node, type, event)
  25604. {
  25605. if (event.target.checked)
  25606. DOMDebuggerAgent.setDOMBreakpoint(node.id, type);
  25607. else
  25608. DOMDebuggerAgent.removeDOMBreakpoint(node.id, type);
  25609. this._saveBreakpoints();
  25610. },
  25611.  
  25612. highlightBreakpoint: function(auxData)
  25613. {
  25614. var breakpointId = this._createBreakpointId(auxData.nodeId, auxData.type);
  25615. var element = this._breakpointElements[breakpointId];
  25616. if (!element)
  25617. return;
  25618. this.expanded = true;
  25619. element.addStyleClass("breakpoint-hit");
  25620. this._highlightedElement = element;
  25621. },
  25622.  
  25623. clearBreakpointHighlight: function()
  25624. {
  25625. if (this._highlightedElement) {
  25626. this._highlightedElement.removeStyleClass("breakpoint-hit");
  25627. delete this._highlightedElement;
  25628. }
  25629. },
  25630.  
  25631. _createBreakpointId: function(nodeId, type)
  25632. {
  25633. return nodeId + ":" + type;
  25634. },
  25635.  
  25636. _saveBreakpoints: function()
  25637. {
  25638. var breakpoints = [];
  25639. var storedBreakpoints = WebInspector.settings.domBreakpoints.get();
  25640. for (var i = 0; i < storedBreakpoints.length; ++i) {
  25641. var breakpoint = storedBreakpoints[i];
  25642. if (breakpoint.url !== this._inspectedURL)
  25643. breakpoints.push(breakpoint);
  25644. }
  25645. for (var id in this._breakpointElements) {
  25646. var element = this._breakpointElements[id];
  25647. breakpoints.push({ url: this._inspectedURL, path: element._node.path(), type: element._type, enabled: element._checkboxElement.checked });
  25648. }
  25649. WebInspector.settings.domBreakpoints.set(breakpoints);
  25650. },
  25651.  
  25652. restoreBreakpoints: function()
  25653. {
  25654. var pathToBreakpoints = {};
  25655.  
  25656. function didPushNodeByPathToFrontend(path, nodeId)
  25657. {
  25658. var node = WebInspector.domAgent.nodeForId(nodeId);
  25659. if (!node)
  25660. return;
  25661.  
  25662. var breakpoints = pathToBreakpoints[path];
  25663. for (var i = 0; i < breakpoints.length; ++i)
  25664. this._setBreakpoint(node, breakpoints[i].type, breakpoints[i].enabled);
  25665. }
  25666.  
  25667. var breakpoints = WebInspector.settings.domBreakpoints.get();
  25668. for (var i = 0; i < breakpoints.length; ++i) {
  25669. var breakpoint = breakpoints[i];
  25670. if (breakpoint.url !== this._inspectedURL)
  25671. continue;
  25672. var path = breakpoint.path;
  25673. if (!pathToBreakpoints[path]) {
  25674. pathToBreakpoints[path] = [];
  25675. WebInspector.domAgent.pushNodeByPathToFrontend(path, didPushNodeByPathToFrontend.bind(this, path));
  25676. }
  25677. pathToBreakpoints[path].push(breakpoint);
  25678. }
  25679. },
  25680.  
  25681. __proto__: WebInspector.NativeBreakpointsSidebarPane.prototype
  25682. }
  25683.  
  25684.  
  25685. WebInspector.domBreakpointsSidebarPane = null;
  25686.  
  25687.  
  25688.  
  25689.  
  25690.  
  25691.  
  25692. WebInspector.Color = function(str)
  25693. {
  25694. this.value = str;
  25695. this._parse();
  25696. }
  25697.  
  25698.  
  25699. WebInspector.Color.fromRGBA = function(r, g, b, a)
  25700. {
  25701. return new WebInspector.Color("rgba(" + r + "," + g + "," + b + "," + (typeof a === "undefined" ? 1 : a) + ")");
  25702. }
  25703.  
  25704. WebInspector.Color.fromRGB = function(r, g, b)
  25705. {
  25706. return new WebInspector.Color("rgb(" + r + "," + g + "," + b + ")");
  25707. }
  25708.  
  25709. WebInspector.Color.prototype = {
  25710.  
  25711. get shorthex()
  25712. {
  25713. if ("_short" in this)
  25714. return this._short;
  25715.  
  25716. if (!this.simple)
  25717. return "";
  25718.  
  25719. var hex = this.hex;
  25720. if (hex.charAt(0) === hex.charAt(1) && hex.charAt(2) === hex.charAt(3) && hex.charAt(4) === hex.charAt(5))
  25721. this._short = hex.charAt(0) + hex.charAt(2) + hex.charAt(4);
  25722. else
  25723. this._short = hex;
  25724.  
  25725. return this._short;
  25726. },
  25727.  
  25728.  
  25729. get hex()
  25730. {
  25731. if (!this.simple)
  25732. return "";
  25733.  
  25734. return this._hex;
  25735. },
  25736.  
  25737. set hex(x)
  25738. {
  25739. this._hex = x;
  25740. },
  25741.  
  25742.  
  25743. get rgb()
  25744. {
  25745. if (this._rgb)
  25746. return this._rgb;
  25747.  
  25748. if (this.simple)
  25749. this._rgb = this._hexToRGB(this.hex);
  25750. else {
  25751. var rgba = this.rgba;
  25752. this._rgb = [rgba[0], rgba[1], rgba[2]];
  25753. }
  25754.  
  25755. return this._rgb;
  25756. },
  25757.  
  25758. set rgb(x)
  25759. {
  25760. this._rgb = x;
  25761. },
  25762.  
  25763.  
  25764. get hsl()
  25765. {
  25766. if (this._hsl)
  25767. return this._hsl;
  25768.  
  25769. this._hsl = this._rgbToHSL(this.rgb);
  25770. return this._hsl;
  25771. },
  25772.  
  25773. set hsl(x)
  25774. {
  25775. this._hsl = x;
  25776. },
  25777.  
  25778.  
  25779. get nickname()
  25780. {
  25781. if (typeof this._nickname !== "undefined") 
  25782. return this._nickname;
  25783. else
  25784. return "";
  25785. },
  25786.  
  25787. set nickname(x)
  25788. {
  25789. this._nickname = x;
  25790. },
  25791.  
  25792.  
  25793. get rgba()
  25794. {
  25795. return this._rgba;
  25796. },
  25797.  
  25798. set rgba(x)
  25799. {
  25800. this._rgba = x;
  25801. },
  25802.  
  25803.  
  25804. get hsla()
  25805. {
  25806. return this._hsla;
  25807. },
  25808.  
  25809. set hsla(x)
  25810. {
  25811. this._hsla = x;
  25812. },
  25813.  
  25814.  
  25815. hasShortHex: function()
  25816. {
  25817. var shorthex = this.shorthex;
  25818. return (!!shorthex && shorthex.length === 3);
  25819. },
  25820.  
  25821.  
  25822. toString: function(format)
  25823. {
  25824. if (!format)
  25825. format = this.format;
  25826.  
  25827. switch (format) {
  25828. case "original":
  25829. return this.value;
  25830. case "rgb":
  25831. return "rgb(" + this.rgb.join(", ") + ")";
  25832. case "rgba":
  25833. return "rgba(" + this.rgba.join(", ") + ")";
  25834. case "hsl":
  25835. var hsl = this.hsl;
  25836. return "hsl(" + hsl[0] + ", " + hsl[1] + "%, " + hsl[2] + "%)";
  25837. case "hsla":
  25838. var hsla = this.hsla;
  25839. return "hsla(" + hsla[0] + ", " + hsla[1] + "%, " + hsla[2] + "%, " + hsla[3] + ")";
  25840. case "hex":
  25841. return "#" + this.hex;
  25842. case "shorthex":
  25843. return "#" + this.shorthex;
  25844. case "nickname":
  25845. return this.nickname;
  25846. }
  25847.  
  25848. throw "invalid color format";
  25849. },
  25850.  
  25851.  
  25852. toProtocolRGBA: function()
  25853. {
  25854. if (this._protocolRGBA)
  25855. return this._protocolRGBA;
  25856.  
  25857. var components = this.rgba;
  25858. if (components)
  25859. this._protocolRGBA = { r: Number(components[0]), g: Number(components[1]), b: Number(components[2]), a: Number(components[3]) };
  25860. else {
  25861. components = this.rgb;
  25862. this._protocolRGBA = { r: Number(components[0]), g: Number(components[1]), b: Number(components[2]) };
  25863. }
  25864. return this._protocolRGBA;
  25865. },
  25866.  
  25867.  
  25868. _clamp: function(value, min, max)
  25869. {
  25870. if (value < min)
  25871. return min;
  25872. if (value > max)
  25873. return max;
  25874. return value;
  25875. },
  25876.  
  25877.  
  25878. _individualRGBValueToFloatValue: function(rgbValue)
  25879. {
  25880. if (typeof rgbValue === "number")
  25881. return this._clamp(rgbValue, 0, 255);
  25882.  
  25883. if (rgbValue.indexOf("%") === -1) {
  25884. var intValue = parseInt(rgbValue, 10);
  25885. return this._clamp(intValue, 0, 255);
  25886. }
  25887.  
  25888. var percentValue = parseFloat(rgbValue);
  25889. return this._clamp(percentValue, 0, 100) * 2.55;
  25890. },
  25891.  
  25892.  
  25893. _individualRGBValueToHexValue: function(rgbValue)
  25894. {
  25895. var floatValue = this._individualRGBValueToFloatValue(rgbValue);
  25896. var hex = Math.round(floatValue).toString(16);
  25897. if (hex.length === 1)
  25898. hex = "0" + hex;
  25899. return hex;
  25900. },
  25901.  
  25902.  
  25903. _rgbStringsToHex: function(rgb)
  25904. {
  25905. var r = this._individualRGBValueToHexValue(rgb[0]);
  25906. var g = this._individualRGBValueToHexValue(rgb[1]);
  25907. var b = this._individualRGBValueToHexValue(rgb[2]);
  25908. return (r + g + b).toUpperCase();
  25909. },
  25910.  
  25911.  
  25912. _rgbToHex: function(rgb)
  25913. {
  25914. var r = this._individualRGBValueToHexValue(rgb[0]);
  25915. var g = this._individualRGBValueToHexValue(rgb[1]);
  25916. var b = this._individualRGBValueToHexValue(rgb[2]);
  25917. return (r + g + b).toUpperCase();
  25918. },
  25919.  
  25920.  
  25921. _hexToRGB: function(hex)
  25922. {
  25923. var r = parseInt(hex.substring(0,2), 16);
  25924. var g = parseInt(hex.substring(2,4), 16);
  25925. var b = parseInt(hex.substring(4,6), 16);
  25926.  
  25927. return [r, g, b];
  25928. },
  25929.  
  25930.  
  25931. _rgbToHSL: function(rgb)
  25932. {
  25933. var r = this._individualRGBValueToFloatValue(rgb[0]) / 255;
  25934. var g = this._individualRGBValueToFloatValue(rgb[1]) / 255;
  25935. var b = this._individualRGBValueToFloatValue(rgb[2]) / 255;
  25936. var max = Math.max(r, g, b);
  25937. var min = Math.min(r, g, b);
  25938. var diff = max - min;
  25939. var add = max + min;
  25940.  
  25941. if (min === max)
  25942. var h = 0;
  25943. else if (r === max)
  25944. var h = ((60 * (g - b) / diff) + 360) % 360;
  25945. else if (g === max)
  25946. var h = (60 * (b - r) / diff) + 120;
  25947. else
  25948. var h = (60 * (r - g) / diff) + 240;
  25949.  
  25950. var l = 0.5 * add;
  25951.  
  25952. if (l === 0)
  25953. var s = 0;
  25954. else if (l === 1)
  25955. var s = 1;
  25956. else if (l <= 0.5)
  25957. var s = diff / add;
  25958. else
  25959. var s = diff / (2 - add);
  25960.  
  25961. h = Math.round(h);
  25962. s = Math.round(s*100);
  25963. l = Math.round(l*100);
  25964.  
  25965. return [h, s, l];
  25966. },
  25967.  
  25968.  
  25969. _hslToRGB: function(hsl)
  25970. {
  25971. var h = parseFloat(hsl[0]) / 360;
  25972. var s = parseFloat(hsl[1]) / 100;
  25973. var l = parseFloat(hsl[2]) / 100;
  25974.  
  25975. if (s < 0)
  25976. s = 0;
  25977.  
  25978. if (l <= 0.5)
  25979. var q = l * (1 + s);
  25980. else
  25981. var q = l + s - (l * s);
  25982.  
  25983. var p = 2 * l - q;
  25984.  
  25985. var tr = h + (1 / 3);
  25986. var tg = h;
  25987. var tb = h - (1 / 3);
  25988.  
  25989. var r = Math.round(hueToRGB(p, q, tr) * 255);
  25990. var g = Math.round(hueToRGB(p, q, tg) * 255);
  25991. var b = Math.round(hueToRGB(p, q, tb) * 255);
  25992. return [r, g, b];
  25993.  
  25994. function hueToRGB(p, q, h) {
  25995. if (h < 0)
  25996. h += 1;
  25997. else if (h > 1)
  25998. h -= 1;
  25999.  
  26000. if ((h * 6) < 1)
  26001. return p + (q - p) * h * 6;
  26002. else if ((h * 2) < 1)
  26003. return q;
  26004. else if ((h * 3) < 2)
  26005. return p + (q - p) * ((2 / 3) - h) * 6;
  26006. else
  26007. return p;
  26008. }
  26009. },
  26010.  
  26011.  
  26012. _rgbaToHSLA: function(rgba, alpha)
  26013. {
  26014. var hsl = this._rgbToHSL(rgba)
  26015. hsl.push(alpha);
  26016. return hsl;
  26017. },
  26018.  
  26019.  
  26020. _hslaToRGBA: function(hsla, alpha)
  26021. {
  26022. var rgb = this._hslToRGB(hsla);
  26023. rgb.push(alpha);
  26024. return rgb;
  26025. },
  26026.  
  26027. _parse: function()
  26028. {
  26029.  
  26030. var value = this.value.toLowerCase().replace(/%|\s+/g, "");
  26031. if (value in WebInspector.Color.AdvancedNickNames) {
  26032. this.format = "nickname";
  26033. var set = WebInspector.Color.AdvancedNickNames[value];
  26034. this.simple = false;
  26035. this.rgba = set[0];
  26036. this.hsla = set[1];
  26037. this.nickname = set[2];
  26038. this.alpha = set[0][3];
  26039. return;
  26040. }
  26041.  
  26042.  
  26043. var simple = /^(?:#([0-9a-f]{3,6})|rgb\(([^)]+)\)|(\w+)|hsl\(([^)]+)\))$/i;
  26044. var match = this.value.match(simple);
  26045. if (match) {
  26046. this.simple = true;
  26047.  
  26048. if (match[1]) { 
  26049. var hex = match[1].toUpperCase();
  26050. if (hex.length === 3) {
  26051. this.format = "shorthex";
  26052. this.hex = hex.charAt(0) + hex.charAt(0) + hex.charAt(1) + hex.charAt(1) + hex.charAt(2) + hex.charAt(2);
  26053. } else {
  26054. this.format = "hex";
  26055. this.hex = hex;
  26056. }
  26057. } else if (match[2]) { 
  26058. this.format = "rgb";
  26059. var rgb = match[2].split(/\s*,\s*/);
  26060. this.rgb = rgb;
  26061. this.hex = this._rgbStringsToHex(rgb);
  26062. } else if (match[3]) { 
  26063. var nickname = match[3].toLowerCase();
  26064. if (nickname in WebInspector.Color.Nicknames) {
  26065. this.format = "nickname";
  26066. this.hex = WebInspector.Color.Nicknames[nickname];
  26067. } else 
  26068. throw "unknown color name";
  26069. } else if (match[4]) { 
  26070. this.format = "hsl";
  26071. var hsl = match[4].replace(/%/g, "").split(/\s*,\s*/);
  26072. this.hsl = hsl;
  26073. this.rgb = this._hslToRGB(hsl);
  26074. this.hex = this._rgbToHex(this.rgb);
  26075. }
  26076.  
  26077.  
  26078. var hex = this.hex;
  26079. if (hex && hex in WebInspector.Color.HexTable) {
  26080. var set = WebInspector.Color.HexTable[hex];
  26081. this.rgb = set[0];
  26082. this.hsl = set[1];
  26083. this.nickname = set[2];
  26084. }
  26085.  
  26086. return;
  26087. }
  26088.  
  26089.  
  26090. var advanced = /^(?:rgba\(([^)]+)\)|hsla\(([^)]+)\))$/;
  26091. match = this.value.match(advanced);
  26092. if (match) {
  26093. this.simple = false;
  26094. if (match[1]) { 
  26095. this.format = "rgba";
  26096. this.rgba = match[1].split(/\s*,\s*/);
  26097. this.rgba[3] = this.alpha = this._clamp(this.rgba[3], 0, 1);
  26098. this.hsla = this._rgbaToHSLA(this.rgba, this.alpha);
  26099. } else if (match[2]) { 
  26100. this.format = "hsla";
  26101. this.hsla = match[2].replace(/%/g, "").split(/\s*,\s*/);
  26102. this.hsla[3] = this.alpha = this._clamp(this.hsla[3], 0, 1);
  26103. this.rgba = this._hslaToRGBA(this.hsla, this.alpha);
  26104. }
  26105.  
  26106. return;
  26107. }
  26108.  
  26109.  
  26110. throw "could not parse color";
  26111. }
  26112. }
  26113.  
  26114.  
  26115. WebInspector.Color.HexTable = {
  26116. "000000": [[0, 0, 0], [0, 0, 0], "black"],
  26117. "000080": [[0, 0, 128], [240, 100, 25], "navy"],
  26118. "00008B": [[0, 0, 139], [240, 100, 27], "darkBlue"],
  26119. "0000CD": [[0, 0, 205], [240, 100, 40], "mediumBlue"],
  26120. "0000FF": [[0, 0, 255], [240, 100, 50], "blue"],
  26121. "006400": [[0, 100, 0], [120, 100, 20], "darkGreen"],
  26122. "008000": [[0, 128, 0], [120, 100, 25], "green"],
  26123. "008080": [[0, 128, 128], [180, 100, 25], "teal"],
  26124. "008B8B": [[0, 139, 139], [180, 100, 27], "darkCyan"],
  26125. "00BFFF": [[0, 191, 255], [195, 100, 50], "deepSkyBlue"],
  26126. "00CED1": [[0, 206, 209], [181, 100, 41], "darkTurquoise"],
  26127. "00FA9A": [[0, 250, 154], [157, 100, 49], "mediumSpringGreen"],
  26128. "00FF00": [[0, 255, 0], [120, 100, 50], "lime"],
  26129. "00FF7F": [[0, 255, 127], [150, 100, 50], "springGreen"],
  26130. "00FFFF": [[0, 255, 255], [180, 100, 50], "cyan"],
  26131. "191970": [[25, 25, 112], [240, 64, 27], "midnightBlue"],
  26132. "1E90FF": [[30, 144, 255], [210, 100, 56], "dodgerBlue"],
  26133. "20B2AA": [[32, 178, 170], [177, 70, 41], "lightSeaGreen"],
  26134. "228B22": [[34, 139, 34], [120, 61, 34], "forestGreen"],
  26135. "2E8B57": [[46, 139, 87], [146, 50, 36], "seaGreen"],
  26136. "2F4F4F": [[47, 79, 79], [180, 25, 25], "darkSlateGray"],
  26137. "32CD32": [[50, 205, 50], [120, 61, 50], "limeGreen"],
  26138. "3CB371": [[60, 179, 113], [147, 50, 47], "mediumSeaGreen"],
  26139. "40E0D0": [[64, 224, 208], [174, 72, 56], "turquoise"],
  26140. "4169E1": [[65, 105, 225], [225, 73, 57], "royalBlue"],
  26141. "4682B4": [[70, 130, 180], [207, 44, 49], "steelBlue"],
  26142. "483D8B": [[72, 61, 139], [248, 39, 39], "darkSlateBlue"],
  26143. "48D1CC": [[72, 209, 204], [178, 60, 55], "mediumTurquoise"],
  26144. "4B0082": [[75, 0, 130], [275, 100, 25], "indigo"],
  26145. "556B2F": [[85, 107, 47], [82, 39, 30], "darkOliveGreen"],
  26146. "5F9EA0": [[95, 158, 160], [182, 25, 50], "cadetBlue"],
  26147. "6495ED": [[100, 149, 237], [219, 79, 66], "cornflowerBlue"],
  26148. "66CDAA": [[102, 205, 170], [160, 51, 60], "mediumAquaMarine"],
  26149. "696969": [[105, 105, 105], [0, 0, 41], "dimGray"],
  26150. "6A5ACD": [[106, 90, 205], [248, 53, 58], "slateBlue"],
  26151. "6B8E23": [[107, 142, 35], [80, 60, 35], "oliveDrab"],
  26152. "708090": [[112, 128, 144], [210, 13, 50], "slateGray"],
  26153. "778899": [[119, 136, 153], [210, 14, 53], "lightSlateGray"],
  26154. "7B68EE": [[123, 104, 238], [249, 80, 67], "mediumSlateBlue"],
  26155. "7CFC00": [[124, 252, 0], [90, 100, 49], "lawnGreen"],
  26156. "7FFF00": [[127, 255, 0], [90, 100, 50], "chartreuse"],
  26157. "7FFFD4": [[127, 255, 212], [160, 100, 75], "aquamarine"],
  26158. "800000": [[128, 0, 0], [0, 100, 25], "maroon"],
  26159. "800080": [[128, 0, 128], [300, 100, 25], "purple"],
  26160. "808000": [[128, 128, 0], [60, 100, 25], "olive"],
  26161. "808080": [[128, 128, 128], [0, 0, 50], "gray"],
  26162. "87CEEB": [[135, 206, 235], [197, 71, 73], "skyBlue"],
  26163. "87CEFA": [[135, 206, 250], [203, 92, 75], "lightSkyBlue"],
  26164. "8A2BE2": [[138, 43, 226], [271, 76, 53], "blueViolet"],
  26165. "8B0000": [[139, 0, 0], [0, 100, 27], "darkRed"],
  26166. "8B008B": [[139, 0, 139], [300, 100, 27], "darkMagenta"],
  26167. "8B4513": [[139, 69, 19], [25, 76, 31], "saddleBrown"],
  26168. "8FBC8F": [[143, 188, 143], [120, 25, 65], "darkSeaGreen"],
  26169. "90EE90": [[144, 238, 144], [120, 73, 75], "lightGreen"],
  26170. "9370D8": [[147, 112, 219], [260, 60, 65], "mediumPurple"],
  26171. "9400D3": [[148, 0, 211], [282, 100, 41], "darkViolet"],
  26172. "98FB98": [[152, 251, 152], [120, 93, 79], "paleGreen"],
  26173. "9932CC": [[153, 50, 204], [280, 61, 50], "darkOrchid"],
  26174. "9ACD32": [[154, 205, 50], [80, 61, 50], "yellowGreen"],
  26175. "A0522D": [[160, 82, 45], [19, 56, 40], "sienna"],
  26176. "A52A2A": [[165, 42, 42], [0, 59, 41], "brown"],
  26177. "A9A9A9": [[169, 169, 169], [0, 0, 66], "darkGray"],
  26178. "ADD8E6": [[173, 216, 230], [195, 53, 79], "lightBlue"],
  26179. "ADFF2F": [[173, 255, 47], [84, 100, 59], "greenYellow"],
  26180. "AFEEEE": [[175, 238, 238], [180, 65, 81], "paleTurquoise"],
  26181. "B0C4DE": [[176, 196, 222], [214, 41, 78], "lightSteelBlue"],
  26182. "B0E0E6": [[176, 224, 230], [187, 52, 80], "powderBlue"],
  26183. "B22222": [[178, 34, 34], [0, 68, 42], "fireBrick"],
  26184. "B8860B": [[184, 134, 11], [43, 89, 38], "darkGoldenrod"],
  26185. "BA55D3": [[186, 85, 211], [288, 59, 58], "mediumOrchid"],
  26186. "BC8F8F": [[188, 143, 143], [0, 25, 65], "rosyBrown"],
  26187. "BDB76B": [[189, 183, 107], [56, 38, 58], "darkKhaki"],
  26188. "C0C0C0": [[192, 192, 192], [0, 0, 75], "silver"],
  26189. "C71585": [[199, 21, 133], [322, 81, 43], "mediumVioletRed"],
  26190. "CD5C5C": [[205, 92, 92], [0, 53, 58], "indianRed"],
  26191. "CD853F": [[205, 133, 63], [30, 59, 53], "peru"],
  26192. "D2691E": [[210, 105, 30], [25, 75, 47], "chocolate"],
  26193. "D2B48C": [[210, 180, 140], [34, 44, 69], "tan"],
  26194. "D3D3D3": [[211, 211, 211], [0, 0, 83], "lightGrey"],
  26195. "D87093": [[219, 112, 147], [340, 60, 65], "paleVioletRed"],
  26196. "D8BFD8": [[216, 191, 216], [300, 24, 80], "thistle"],
  26197. "DA70D6": [[218, 112, 214], [302, 59, 65], "orchid"],
  26198. "DAA520": [[218, 165, 32], [43, 74, 49], "goldenrod"],
  26199. "DC143C": [[237, 164, 61], [35, 83, 58], "crimson"],
  26200. "DCDCDC": [[220, 220, 220], [0, 0, 86], "gainsboro"],
  26201. "DDA0DD": [[221, 160, 221], [300, 47, 75], "plum"],
  26202. "DEB887": [[222, 184, 135], [34, 57, 70], "burlyWood"],
  26203. "E0FFFF": [[224, 255, 255], [180, 100, 94], "lightCyan"],
  26204. "E6E6FA": [[230, 230, 250], [240, 67, 94], "lavender"],
  26205. "E9967A": [[233, 150, 122], [15, 72, 70], "darkSalmon"],
  26206. "EE82EE": [[238, 130, 238], [300, 76, 72], "violet"],
  26207. "EEE8AA": [[238, 232, 170], [55, 67, 80], "paleGoldenrod"],
  26208. "F08080": [[240, 128, 128], [0, 79, 72], "lightCoral"],
  26209. "F0E68C": [[240, 230, 140], [54, 77, 75], "khaki"],
  26210. "F0F8FF": [[240, 248, 255], [208, 100, 97], "aliceBlue"],
  26211. "F0FFF0": [[240, 255, 240], [120, 100, 97], "honeyDew"],
  26212. "F0FFFF": [[240, 255, 255], [180, 100, 97], "azure"],
  26213. "F4A460": [[244, 164, 96], [28, 87, 67], "sandyBrown"],
  26214. "F5DEB3": [[245, 222, 179], [39, 77, 83], "wheat"],
  26215. "F5F5DC": [[245, 245, 220], [60, 56, 91], "beige"],
  26216. "F5F5F5": [[245, 245, 245], [0, 0, 96], "whiteSmoke"],
  26217. "F5FFFA": [[245, 255, 250], [150, 100, 98], "mintCream"],
  26218. "F8F8FF": [[248, 248, 255], [240, 100, 99], "ghostWhite"],
  26219. "FA8072": [[250, 128, 114], [6, 93, 71], "salmon"],
  26220. "FAEBD7": [[250, 235, 215], [34, 78, 91], "antiqueWhite"],
  26221. "FAF0E6": [[250, 240, 230], [30, 67, 94], "linen"],
  26222. "FAFAD2": [[250, 250, 210], [60, 80, 90], "lightGoldenrodYellow"],
  26223. "FDF5E6": [[253, 245, 230], [39, 85, 95], "oldLace"],
  26224. "FF0000": [[255, 0, 0], [0, 100, 50], "red"],
  26225. "FF00FF": [[255, 0, 255], [300, 100, 50], "magenta"],
  26226. "FF1493": [[255, 20, 147], [328, 100, 54], "deepPink"],
  26227. "FF4500": [[255, 69, 0], [16, 100, 50], "orangeRed"],
  26228. "FF6347": [[255, 99, 71], [9, 100, 64], "tomato"],
  26229. "FF69B4": [[255, 105, 180], [330, 100, 71], "hotPink"],
  26230. "FF7F50": [[255, 127, 80], [16, 100, 66], "coral"],
  26231. "FF8C00": [[255, 140, 0], [33, 100, 50], "darkOrange"],
  26232. "FFA07A": [[255, 160, 122], [17, 100, 74], "lightSalmon"],
  26233. "FFA500": [[255, 165, 0], [39, 100, 50], "orange"],
  26234. "FFB6C1": [[255, 182, 193], [351, 100, 86], "lightPink"],
  26235. "FFC0CB": [[255, 192, 203], [350, 100, 88], "pink"],
  26236. "FFD700": [[255, 215, 0], [51, 100, 50], "gold"],
  26237. "FFDAB9": [[255, 218, 185], [28, 100, 86], "peachPuff"],
  26238. "FFDEAD": [[255, 222, 173], [36, 100, 84], "navajoWhite"],
  26239. "FFE4B5": [[255, 228, 181], [38, 100, 85], "moccasin"],
  26240. "FFE4C4": [[255, 228, 196], [33, 100, 88], "bisque"],
  26241. "FFE4E1": [[255, 228, 225], [6, 100, 94], "mistyRose"],
  26242. "FFEBCD": [[255, 235, 205], [36, 100, 90], "blanchedAlmond"],
  26243. "FFEFD5": [[255, 239, 213], [37, 100, 92], "papayaWhip"],
  26244. "FFF0F5": [[255, 240, 245], [340, 100, 97], "lavenderBlush"],
  26245. "FFF5EE": [[255, 245, 238], [25, 100, 97], "seaShell"],
  26246. "FFF8DC": [[255, 248, 220], [48, 100, 93], "cornsilk"],
  26247. "FFFACD": [[255, 250, 205], [54, 100, 90], "lemonChiffon"],
  26248. "FFFAF0": [[255, 250, 240], [40, 100, 97], "floralWhite"],
  26249. "FFFAFA": [[255, 250, 250], [0, 100, 99], "snow"],
  26250. "FFFF00": [[255, 255, 0], [60, 100, 50], "yellow"],
  26251. "FFFFE0": [[255, 255, 224], [60, 100, 94], "lightYellow"],
  26252. "FFFFF0": [[255, 255, 240], [60, 100, 97], "ivory"],
  26253. "FFFFFF": [[255, 255, 255], [0, 100, 100], "white"]
  26254. };
  26255.  
  26256.  
  26257. WebInspector.Color.Nicknames = {
  26258. "aliceblue": "F0F8FF",
  26259. "antiquewhite": "FAEBD7",
  26260. "aqua": "00FFFF",
  26261. "aquamarine": "7FFFD4",
  26262. "azure": "F0FFFF",
  26263. "beige": "F5F5DC",
  26264. "bisque": "FFE4C4",
  26265. "black": "000000",
  26266. "blanchedalmond": "FFEBCD",
  26267. "blue": "0000FF",
  26268. "blueviolet": "8A2BE2",
  26269. "brown": "A52A2A",
  26270. "burlywood": "DEB887",
  26271. "cadetblue": "5F9EA0",
  26272. "chartreuse": "7FFF00",
  26273. "chocolate": "D2691E",
  26274. "coral": "FF7F50",
  26275. "cornflowerblue": "6495ED",
  26276. "cornsilk": "FFF8DC",
  26277. "crimson": "DC143C",
  26278. "cyan": "00FFFF",
  26279. "darkblue": "00008B",
  26280. "darkcyan": "008B8B",
  26281. "darkgoldenrod": "B8860B",
  26282. "darkgray": "A9A9A9",
  26283. "darkgreen": "006400",
  26284. "darkkhaki": "BDB76B",
  26285. "darkmagenta": "8B008B",
  26286. "darkolivegreen": "556B2F",
  26287. "darkorange": "FF8C00",
  26288. "darkorchid": "9932CC",
  26289. "darkred": "8B0000",
  26290. "darksalmon": "E9967A",
  26291. "darkseagreen": "8FBC8F",
  26292. "darkslateblue": "483D8B",
  26293. "darkslategray": "2F4F4F",
  26294. "darkturquoise": "00CED1",
  26295. "darkviolet": "9400D3",
  26296. "deeppink": "FF1493",
  26297. "deepskyblue": "00BFFF",
  26298. "dimgray": "696969",
  26299. "dodgerblue": "1E90FF",
  26300. "firebrick": "B22222",
  26301. "floralwhite": "FFFAF0",
  26302. "forestgreen": "228B22",
  26303. "fuchsia": "FF00FF",
  26304. "gainsboro": "DCDCDC",
  26305. "ghostwhite": "F8F8FF",
  26306. "gold": "FFD700",
  26307. "goldenrod": "DAA520",
  26308. "gray": "808080",
  26309. "green": "008000",
  26310. "greenyellow": "ADFF2F",
  26311. "honeydew": "F0FFF0",
  26312. "hotpink": "FF69B4",
  26313. "indianred": "CD5C5C",
  26314. "indigo": "4B0082",
  26315. "ivory": "FFFFF0",
  26316. "khaki": "F0E68C",
  26317. "lavender": "E6E6FA",
  26318. "lavenderblush": "FFF0F5",
  26319. "lawngreen": "7CFC00",
  26320. "lemonchiffon": "FFFACD",
  26321. "lightblue": "ADD8E6",
  26322. "lightcoral": "F08080",
  26323. "lightcyan": "E0FFFF",
  26324. "lightgoldenrodyellow": "FAFAD2",
  26325. "lightgreen": "90EE90",
  26326. "lightgrey": "D3D3D3",
  26327. "lightpink": "FFB6C1",
  26328. "lightsalmon": "FFA07A",
  26329. "lightseagreen": "20B2AA",
  26330. "lightskyblue": "87CEFA",
  26331. "lightslategray": "778899",
  26332. "lightsteelblue": "B0C4DE",
  26333. "lightyellow": "FFFFE0",
  26334. "lime": "00FF00",
  26335. "limegreen": "32CD32",
  26336. "linen": "FAF0E6",
  26337. "magenta": "FF00FF",
  26338. "maroon": "800000",
  26339. "mediumaquamarine": "66CDAA",
  26340. "mediumblue": "0000CD",
  26341. "mediumorchid": "BA55D3",
  26342. "mediumpurple": "9370DB",
  26343. "mediumseagreen": "3CB371",
  26344. "mediumslateblue": "7B68EE",
  26345. "mediumspringgreen": "00FA9A",
  26346. "mediumturquoise": "48D1CC",
  26347. "mediumvioletred": "C71585",
  26348. "midnightblue": "191970",
  26349. "mintcream": "F5FFFA",
  26350. "mistyrose": "FFE4E1",
  26351. "moccasin": "FFE4B5",
  26352. "navajowhite": "FFDEAD",
  26353. "navy": "000080",
  26354. "oldlace": "FDF5E6",
  26355. "olive": "808000",
  26356. "olivedrab": "6B8E23",
  26357. "orange": "FFA500",
  26358. "orangered": "FF4500",
  26359. "orchid": "DA70D6",
  26360. "palegoldenrod": "EEE8AA",
  26361. "palegreen": "98FB98",
  26362. "paleturquoise": "AFEEEE",
  26363. "palevioletred": "DB7093",
  26364. "papayawhip": "FFEFD5",
  26365. "peachpuff": "FFDAB9",
  26366. "peru": "CD853F",
  26367. "pink": "FFC0CB",
  26368. "plum": "DDA0DD",
  26369. "powderblue": "B0E0E6",
  26370. "purple": "800080",
  26371. "red": "FF0000",
  26372. "rosybrown": "BC8F8F",
  26373. "royalblue": "4169E1",
  26374. "saddlebrown": "8B4513",
  26375. "salmon": "FA8072",
  26376. "sandybrown": "F4A460",
  26377. "seagreen": "2E8B57",
  26378. "seashell": "FFF5EE",
  26379. "sienna": "A0522D",
  26380. "silver": "C0C0C0",
  26381. "skyblue": "87CEEB",
  26382. "slateblue": "6A5ACD",
  26383. "slategray": "708090",
  26384. "snow": "FFFAFA",
  26385. "springgreen": "00FF7F",
  26386. "steelblue": "4682B4",
  26387. "tan": "D2B48C",
  26388. "teal": "008080",
  26389. "thistle": "D8BFD8",
  26390. "tomato": "FF6347",
  26391. "turquoise": "40E0D0",
  26392. "violet": "EE82EE",
  26393. "wheat": "F5DEB3",
  26394. "white": "FFFFFF",
  26395. "whitesmoke": "F5F5F5",
  26396. "yellow": "FFFF00",
  26397. "yellowgreen": "9ACD32"
  26398. };
  26399.  
  26400.  
  26401. WebInspector.Color.AdvancedNickNames = {
  26402. "transparent": [[0, 0, 0, 0], [0, 0, 0, 0], "transparent"],
  26403. "rgba(0,0,0,0)": [[0, 0, 0, 0], [0, 0, 0, 0], "transparent"],
  26404. "hsla(0,0,0,0)": [[0, 0, 0, 0], [0, 0, 0, 0], "transparent"],
  26405. };
  26406.  
  26407. WebInspector.Color.PageHighlight = {
  26408. Content: WebInspector.Color.fromRGBA(111, 168, 220, .66),
  26409. ContentLight: WebInspector.Color.fromRGBA(111, 168, 220, .5),
  26410. ContentOutline: WebInspector.Color.fromRGBA(9, 83, 148),
  26411. Padding: WebInspector.Color.fromRGBA(147, 196, 125, .55),
  26412. PaddingLight: WebInspector.Color.fromRGBA(147, 196, 125, .4),
  26413. Border: WebInspector.Color.fromRGBA(255, 229, 153, .66),
  26414. BorderLight: WebInspector.Color.fromRGBA(255, 229, 153, .5),
  26415. Margin: WebInspector.Color.fromRGBA(246, 178, 107, .66),
  26416. MarginLight: WebInspector.Color.fromRGBA(246, 178, 107, .5)
  26417. }
  26418.  
  26419. WebInspector.Color.Format = {
  26420. Original: "original",
  26421. Nickname: "nickname",
  26422. HEX: "hex",
  26423. ShortHEX: "shorthex",
  26424. RGB: "rgb",
  26425. RGBA: "rgba",
  26426. HSL: "hsl",
  26427. HSLA: "hsla"
  26428. }
  26429.  
  26430.  
  26431.  
  26432.  
  26433.  
  26434.  
  26435. WebInspector.CSSCompletions = function(properties)
  26436. {
  26437. this._values = [];
  26438. this._longhands = {};
  26439. this._shorthands = {};
  26440. for (var i = 0; i < properties.length; ++i) {
  26441. var property = properties[i];
  26442. if (typeof property === "string") {
  26443. this._values.push(property);
  26444. continue;
  26445. }
  26446.  
  26447. var propertyName = property.name;
  26448. this._values.push(propertyName);
  26449.  
  26450. var longhands = properties[i].longhands;
  26451. if (longhands) {
  26452. this._longhands[propertyName] = longhands;
  26453. for (var j = 0; j < longhands.length; ++j) {
  26454. var longhandName = longhands[j];
  26455. var shorthands = this._shorthands[longhandName];
  26456. if (!shorthands) {
  26457. shorthands = [];
  26458. this._shorthands[longhandName] = shorthands;
  26459. }
  26460. shorthands.push(propertyName);
  26461. }
  26462. }
  26463. }
  26464. this._values.sort();
  26465. }
  26466.  
  26467.  
  26468.  
  26469. WebInspector.CSSCompletions.cssPropertiesMetainfo = null;
  26470.  
  26471. WebInspector.CSSCompletions.requestCSSNameCompletions = function()
  26472. {
  26473. function propertyNamesCallback(error, properties)
  26474. {
  26475. if (!error)
  26476. WebInspector.CSSCompletions.cssPropertiesMetainfo = new WebInspector.CSSCompletions(properties);
  26477. }
  26478. CSSAgent.getSupportedCSSProperties(propertyNamesCallback);
  26479. }
  26480.  
  26481. WebInspector.CSSCompletions.cssPropertiesMetainfoKeySet = function()
  26482. {
  26483. if (!WebInspector.CSSCompletions._cssPropertiesMetainfoKeySet)
  26484. WebInspector.CSSCompletions._cssPropertiesMetainfoKeySet = WebInspector.CSSCompletions.cssPropertiesMetainfo.keySet();
  26485. return WebInspector.CSSCompletions._cssPropertiesMetainfoKeySet;
  26486. }
  26487.  
  26488.  
  26489. WebInspector.CSSCompletions.Weight = {
  26490. "-webkit-animation": 1,
  26491. "-webkit-animation-duration": 1,
  26492. "-webkit-animation-iteration-count": 1,
  26493. "-webkit-animation-name": 1,
  26494. "-webkit-animation-timing-function": 1,
  26495. "-webkit-appearance": 1,
  26496. "-webkit-background-clip": 2,
  26497. "-webkit-border-horizontal-spacing": 1,
  26498. "-webkit-border-vertical-spacing": 1,
  26499. "-webkit-box-shadow": 24,
  26500. "-webkit-font-smoothing": 2,
  26501. "-webkit-transform": 1,
  26502. "-webkit-transition": 8,
  26503. "-webkit-transition-delay": 7,
  26504. "-webkit-transition-duration": 7,
  26505. "-webkit-transition-property": 7,
  26506. "-webkit-transition-timing-function": 6,
  26507. "-webkit-user-select": 1,
  26508. "background": 222,
  26509. "background-attachment": 144,
  26510. "background-clip": 143,
  26511. "background-color": 222,
  26512. "background-image": 201,
  26513. "background-origin": 142,
  26514. "background-size": 25,
  26515. "border": 121,
  26516. "border-bottom": 121,
  26517. "border-bottom-color": 121,
  26518. "border-bottom-left-radius": 50,
  26519. "border-bottom-right-radius": 50,
  26520. "border-bottom-style": 114,
  26521. "border-bottom-width": 120,
  26522. "border-collapse": 3,
  26523. "border-left": 95,
  26524. "border-left-color": 95,
  26525. "border-left-style": 89,
  26526. "border-left-width": 94,
  26527. "border-radius": 50,
  26528. "border-right": 93,
  26529. "border-right-color": 93,
  26530. "border-right-style": 88,
  26531. "border-right-width": 93,
  26532. "border-top": 111,
  26533. "border-top-color": 111,
  26534. "border-top-left-radius": 49,
  26535. "border-top-right-radius": 49,
  26536. "border-top-style": 104,
  26537. "border-top-width": 109,
  26538. "bottom": 16,
  26539. "box-shadow": 25,
  26540. "box-sizing": 2,
  26541. "clear": 23,
  26542. "color": 237,
  26543. "cursor": 34,
  26544. "direction": 4,
  26545. "display": 210,
  26546. "fill": 2,
  26547. "filter": 1,
  26548. "float": 105,
  26549. "font": 174,
  26550. "font-family": 25,
  26551. "font-size": 174,
  26552. "font-style": 9,
  26553. "font-weight": 89,
  26554. "height": 161,
  26555. "left": 54,
  26556. "letter-spacing": 3,
  26557. "line-height": 75,
  26558. "list-style": 17,
  26559. "list-style-image": 8,
  26560. "list-style-position": 8,
  26561. "list-style-type": 17,
  26562. "margin": 241,
  26563. "margin-bottom": 226,
  26564. "margin-left": 225,
  26565. "margin-right": 213,
  26566. "margin-top": 241,
  26567. "max-height": 5,
  26568. "max-width": 11,
  26569. "min-height": 9,
  26570. "min-width": 6,
  26571. "opacity": 24,
  26572. "outline": 10,
  26573. "outline-color": 10,
  26574. "outline-style": 10,
  26575. "outline-width": 10,
  26576. "overflow": 57,
  26577. "overflow-x": 56,
  26578. "overflow-y": 57,
  26579. "padding": 216,
  26580. "padding-bottom": 208,
  26581. "padding-left": 216,
  26582. "padding-right": 206,
  26583. "padding-top": 216,
  26584. "position": 136,
  26585. "resize": 1,
  26586. "right": 29,
  26587. "stroke": 1,
  26588. "stroke-width": 1,
  26589. "table-layout": 1,
  26590. "text-align": 66,
  26591. "text-decoration": 53,
  26592. "text-indent": 9,
  26593. "text-overflow": 8,
  26594. "text-shadow": 19,
  26595. "text-transform": 5,
  26596. "top": 71,
  26597. "unicode-bidi": 1,
  26598. "vertical-align": 37,
  26599. "visibility": 11,
  26600. "white-space": 24,
  26601. "width": 255,
  26602. "word-wrap": 6,
  26603. "z-index": 32,
  26604. "zoom": 10
  26605. };
  26606.  
  26607.  
  26608. WebInspector.CSSCompletions.prototype = {
  26609. startsWith: function(prefix)
  26610. {
  26611. var firstIndex = this._firstIndexOfPrefix(prefix);
  26612. if (firstIndex === -1)
  26613. return [];
  26614.  
  26615. var results = [];
  26616. while (firstIndex < this._values.length && this._values[firstIndex].startsWith(prefix))
  26617. results.push(this._values[firstIndex++]);
  26618. return results;
  26619. },
  26620.  
  26621.  
  26622. mostUsedOf: function(properties)
  26623. {
  26624. var maxWeight = 0;
  26625. var index = 0;
  26626. for (var i = 0; i < properties.length; i++) {
  26627. var weight = WebInspector.CSSCompletions.Weight[properties[i]];
  26628. if (weight > maxWeight) {
  26629. maxWeight = weight;
  26630. index = i;
  26631. }
  26632. }
  26633. return index;
  26634. },
  26635.  
  26636. _firstIndexOfPrefix: function(prefix)
  26637. {
  26638. if (!this._values.length)
  26639. return -1;
  26640. if (!prefix)
  26641. return 0;
  26642.  
  26643. var maxIndex = this._values.length - 1;
  26644. var minIndex = 0;
  26645. var foundIndex;
  26646.  
  26647. do {
  26648. var middleIndex = (maxIndex + minIndex) >> 1;
  26649. if (this._values[middleIndex].startsWith(prefix)) {
  26650. foundIndex = middleIndex;
  26651. break;
  26652. }
  26653. if (this._values[middleIndex] < prefix)
  26654. minIndex = middleIndex + 1;
  26655. else
  26656. maxIndex = middleIndex - 1;
  26657. } while (minIndex <= maxIndex);
  26658.  
  26659. if (foundIndex === undefined)
  26660. return -1;
  26661.  
  26662. while (foundIndex && this._values[foundIndex - 1].startsWith(prefix))
  26663. foundIndex--;
  26664.  
  26665. return foundIndex;
  26666. },
  26667.  
  26668. keySet: function()
  26669. {
  26670. if (!this._keySet)
  26671. this._keySet = this._values.keySet();
  26672. return this._keySet;
  26673. },
  26674.  
  26675. next: function(str, prefix)
  26676. {
  26677. return this._closest(str, prefix, 1);
  26678. },
  26679.  
  26680. previous: function(str, prefix)
  26681. {
  26682. return this._closest(str, prefix, -1);
  26683. },
  26684.  
  26685. _closest: function(str, prefix, shift)
  26686. {
  26687. if (!str)
  26688. return "";
  26689.  
  26690. var index = this._values.indexOf(str);
  26691. if (index === -1)
  26692. return "";
  26693.  
  26694. if (!prefix) {
  26695. index = (index + this._values.length + shift) % this._values.length;
  26696. return this._values[index];
  26697. }
  26698.  
  26699. var propertiesWithPrefix = this.startsWith(prefix);
  26700. var j = propertiesWithPrefix.indexOf(str);
  26701. j = (j + propertiesWithPrefix.length + shift) % propertiesWithPrefix.length;
  26702. return propertiesWithPrefix[j];
  26703. },
  26704.  
  26705.  
  26706. longhands: function(shorthand)
  26707. {
  26708. return this._longhands[shorthand];
  26709. },
  26710.  
  26711.  
  26712. shorthands: function(longhand)
  26713. {
  26714. return this._shorthands[longhand];
  26715. }
  26716. }
  26717.  
  26718.  
  26719.  
  26720.  
  26721.  
  26722. WebInspector.CSSKeywordCompletions = {}
  26723.  
  26724. WebInspector.CSSKeywordCompletions.forProperty = function(propertyName)
  26725. {
  26726. var acceptedKeywords = ["initial"];
  26727. if (propertyName in WebInspector.CSSKeywordCompletions._propertyKeywordMap)
  26728. acceptedKeywords = acceptedKeywords.concat(WebInspector.CSSKeywordCompletions._propertyKeywordMap[propertyName]);
  26729. if (propertyName in WebInspector.CSSKeywordCompletions._colorAwareProperties)
  26730. acceptedKeywords = acceptedKeywords.concat(WebInspector.CSSKeywordCompletions._colors);
  26731. if (propertyName in WebInspector.CSSKeywordCompletions.InheritedProperties)
  26732. acceptedKeywords.push("inherit");
  26733. return new WebInspector.CSSCompletions(acceptedKeywords);
  26734. }
  26735.  
  26736. WebInspector.CSSKeywordCompletions.isColorAwareProperty = function(propertyName)
  26737. {
  26738. return WebInspector.CSSKeywordCompletions._colorAwareProperties[propertyName] === true;
  26739. }
  26740.  
  26741. WebInspector.CSSKeywordCompletions.colors = function()
  26742. {
  26743. if (!WebInspector.CSSKeywordCompletions._colorsKeySet)
  26744. WebInspector.CSSKeywordCompletions._colorsKeySet = WebInspector.CSSKeywordCompletions._colors.keySet();
  26745. return WebInspector.CSSKeywordCompletions._colorsKeySet;
  26746. }
  26747.  
  26748.  
  26749. WebInspector.CSSKeywordCompletions.InheritedProperties = [
  26750. "azimuth", "border-collapse", "border-spacing", "caption-side", "color", "cursor", "direction", "elevation",
  26751. "empty-cells", "font-family", "font-size", "font-style", "font-variant", "font-weight", "font", "letter-spacing",
  26752. "line-height", "list-style-image", "list-style-position", "list-style-type", "list-style", "orphans", "pitch-range",
  26753. "pitch", "quotes", "richness", "speak-header", "speak-numeral", "speak-punctuation", "speak", "speech-rate", "stress",
  26754. "text-align", "text-indent", "text-transform", "text-shadow", "visibility", "voice-family", "volume", "white-space", "widows", "word-spacing"
  26755. ].keySet();
  26756.  
  26757. WebInspector.CSSKeywordCompletions._colors = [
  26758. "aqua", "black", "blue", "fuchsia", "gray", "green", "lime", "maroon", "navy", "olive", "orange", "purple", "red",
  26759. "silver", "teal", "white", "yellow", "transparent", "currentcolor", "grey", "aliceblue", "antiquewhite",
  26760. "aquamarine", "azure", "beige", "bisque", "blanchedalmond", "blueviolet", "brown", "burlywood", "cadetblue",
  26761. "chartreuse", "chocolate", "coral", "cornflowerblue", "cornsilk", "crimson", "cyan", "darkblue", "darkcyan",
  26762. "darkgoldenrod", "darkgray", "darkgreen", "darkgrey", "darkkhaki", "darkmagenta", "darkolivegreen", "darkorange",
  26763. "darkorchid", "darkred", "darksalmon", "darkseagreen", "darkslateblue", "darkslategray", "darkslategrey",
  26764. "darkturquoise", "darkviolet", "deeppink", "deepskyblue", "dimgray", "dimgrey", "dodgerblue", "firebrick",
  26765. "floralwhite", "forestgreen", "gainsboro", "ghostwhite", "gold", "goldenrod", "greenyellow", "honeydew", "hotpink",
  26766. "indianred", "indigo", "ivory", "khaki", "lavender", "lavenderblush", "lawngreen", "lemonchiffon", "lightblue",
  26767. "lightcoral", "lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightgrey", "lightpink",
  26768. "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray", "lightslategrey", "lightsteelblue", "lightyellow",
  26769. "limegreen", "linen", "magenta", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple", "mediumseagreen",
  26770. "mediumslateblue", "mediumspringgreen", "mediumturquoise", "mediumvioletred", "midnightblue", "mintcream",
  26771. "mistyrose", "moccasin", "navajowhite", "oldlace", "olivedrab", "orangered", "orchid", "palegoldenrod", "palegreen",
  26772. "paleturquoise", "palevioletred", "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue", "rosybrown",
  26773. "royalblue", "saddlebrown", "salmon", "sandybrown", "seagreen", "seashell", "sienna", "skyblue", "slateblue",
  26774. "slategray", "slategrey", "snow", "springgreen", "steelblue", "tan", "thistle", "tomato", "turquoise", "violet",
  26775. "wheat", "whitesmoke", "yellowgreen"
  26776. ];
  26777.  
  26778. WebInspector.CSSKeywordCompletions._colorAwareProperties = [
  26779. "background", "background-color", "background-image", "border", "border-color", "border-top", "border-right", "border-bottom",
  26780. "border-left", "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", "box-shadow", "color",
  26781. "fill", "outline", "outline-color", "stroke", "text-line-through", "text-line-through-color", "text-overline", "text-overline-color",
  26782. "text-shadow", "text-underline", "text-underline-color", "-webkit-box-shadow", "-webkit-text-emphasis", "-webkit-text-emphasis-color"
  26783. ].keySet();
  26784.  
  26785. WebInspector.CSSKeywordCompletions._propertyKeywordMap = {
  26786. "table-layout": [
  26787. "auto", "fixed"
  26788. ],
  26789. "visibility": [
  26790. "hidden", "visible", "collapse"
  26791. ],
  26792. "background-repeat": [
  26793. "repeat", "repeat-x", "repeat-y", "no-repeat", "space", "round"
  26794. ],
  26795. "text-underline": [
  26796. "none", "dotted", "dashed", "solid", "double", "dot-dash", "dot-dot-dash", "wave"
  26797. ],
  26798. "content": [
  26799. "list-item", "close-quote", "no-close-quote", "no-open-quote", "open-quote"
  26800. ],
  26801. "list-style-image": [
  26802. "none"
  26803. ],
  26804. "clear": [
  26805. "none", "left", "right", "both"
  26806. ],
  26807. "text-underline-mode": [
  26808. "continuous", "skip-white-space"
  26809. ],
  26810. "overflow-x": [
  26811. "hidden", "auto", "visible", "overlay", "scroll"
  26812. ],
  26813. "stroke-linejoin": [
  26814. "round", "miter", "bevel"
  26815. ],
  26816. "baseline-shift": [
  26817. "baseline", "sub", "super"
  26818. ],
  26819. "border-bottom-width": [
  26820. "medium", "thick", "thin"
  26821. ],
  26822. "marquee-speed": [
  26823. "normal", "slow", "fast"
  26824. ],
  26825. "margin-top-collapse": [
  26826. "collapse", "separate", "discard"
  26827. ],
  26828. "max-height": [
  26829. "none"
  26830. ],
  26831. "box-orient": [
  26832. "horizontal", "vertical", "inline-axis", "block-axis"
  26833. ],
  26834. "font-stretch": [
  26835. "normal", "wider", "narrower", "ultra-condensed", "extra-condensed", "condensed", "semi-condensed",
  26836. "semi-expanded", "expanded", "extra-expanded", "ultra-expanded"
  26837. ],
  26838. "-webkit-color-correction": [
  26839. "default", "srgb"
  26840. ],
  26841. "text-underline-style": [
  26842. "none", "dotted", "dashed", "solid", "double", "dot-dash", "dot-dot-dash", "wave"
  26843. ],
  26844. "text-overline-mode": [
  26845. "continuous", "skip-white-space"
  26846. ],
  26847. "-webkit-background-composite": [
  26848. "highlight", "clear", "copy", "source-over", "source-in", "source-out", "source-atop", "destination-over",
  26849. "destination-in", "destination-out", "destination-atop", "xor", "plus-darker", "plus-lighter"
  26850. ],
  26851. "border-left-width": [
  26852. "medium", "thick", "thin"
  26853. ],
  26854. "-webkit-writing-mode": [
  26855. "lr", "rl", "tb", "lr-tb", "rl-tb", "tb-rl", "horizontal-tb", "vertical-rl", "vertical-lr", "horizontal-bt"
  26856. ],
  26857. "text-line-through-mode": [
  26858. "continuous", "skip-white-space"
  26859. ],
  26860. "border-collapse": [
  26861. "collapse", "separate"
  26862. ],
  26863. "page-break-inside": [
  26864. "auto", "avoid"
  26865. ],
  26866. "border-top-width": [
  26867. "medium", "thick", "thin"
  26868. ],
  26869. "outline-color": [
  26870. "invert"
  26871. ],
  26872. "text-line-through-style": [
  26873. "none", "dotted", "dashed", "solid", "double", "dot-dash", "dot-dot-dash", "wave"
  26874. ],
  26875. "outline-style": [
  26876. "none", "hidden", "inset", "groove", "ridge", "outset", "dotted", "dashed", "solid", "double"
  26877. ],
  26878. "cursor": [
  26879. "none", "copy", "auto", "crosshair", "default", "pointer", "move", "vertical-text", "cell", "context-menu",
  26880. "alias", "progress", "no-drop", "not-allowed", "-webkit-zoom-in", "-webkit-zoom-out", "e-resize", "ne-resize",
  26881. "nw-resize", "n-resize", "se-resize", "sw-resize", "s-resize", "w-resize", "ew-resize", "ns-resize",
  26882. "nesw-resize", "nwse-resize", "col-resize", "row-resize", "text", "wait", "help", "all-scroll", "-webkit-grab",
  26883. "-webkit-grabbing"
  26884. ],
  26885. "border-width": [
  26886. "medium", "thick", "thin"
  26887. ],
  26888. "size": [
  26889. "a3", "a4", "a5", "b4", "b5", "landscape", "ledger", "legal", "letter", "portrait"
  26890. ],
  26891. "background-size": [
  26892. "contain", "cover"
  26893. ],
  26894. "direction": [
  26895. "ltr", "rtl"
  26896. ],
  26897. "marquee-direction": [
  26898. "left", "right", "auto", "reverse", "forwards", "backwards", "ahead", "up", "down"
  26899. ],
  26900. "enable-background": [
  26901. "accumulate", "new"
  26902. ],
  26903. "float": [
  26904. "none", "left", "right"
  26905. ],
  26906. "overflow-y": [
  26907. "hidden", "auto", "visible", "overlay", "scroll"
  26908. ],
  26909. "margin-bottom-collapse": [
  26910. "collapse",  "separate", "discard"
  26911. ],
  26912. "box-reflect": [
  26913. "left", "right", "above", "below"
  26914. ],
  26915. "overflow": [
  26916. "hidden", "auto", "visible", "overlay", "scroll"
  26917. ],
  26918. "text-rendering": [
  26919. "auto", "optimizeSpeed", "optimizeLegibility", "geometricPrecision"
  26920. ],
  26921. "text-align": [
  26922. "-webkit-auto", "left", "right", "center", "justify", "-webkit-left", "-webkit-right", "-webkit-center"
  26923. ],
  26924. "list-style-position": [
  26925. "outside", "inside"
  26926. ],
  26927. "margin-bottom": [
  26928. "auto"
  26929. ],
  26930. "color-interpolation": [
  26931. "linearrgb"
  26932. ],
  26933. "background-origin": [
  26934. "border-box", "content-box", "padding-box"
  26935. ],
  26936. "word-wrap": [
  26937. "normal", "break-word"
  26938. ],
  26939. "font-weight": [
  26940. "normal", "bold", "bolder", "lighter", "100", "200", "300", "400", "500", "600", "700", "800", "900"
  26941. ],
  26942. "margin-before-collapse": [
  26943. "collapse", "separate", "discard"
  26944. ],
  26945. "text-overline-width": [
  26946. "normal", "medium", "auto", "thick", "thin"
  26947. ],
  26948. "text-transform": [
  26949. "none", "capitalize", "uppercase", "lowercase"
  26950. ],
  26951. "border-right-style": [
  26952. "none", "hidden", "inset", "groove", "ridge", "outset", "dotted", "dashed", "solid", "double"
  26953. ],
  26954. "border-left-style": [
  26955. "none", "hidden", "inset", "groove", "ridge", "outset", "dotted", "dashed", "solid", "double"
  26956. ],
  26957. "-webkit-text-emphasis": [
  26958. "circle", "filled", "open", "dot", "double-circle", "triangle", "sesame"
  26959. ],
  26960. "font-style": [
  26961. "italic", "oblique", "normal"
  26962. ],
  26963. "speak": [
  26964. "none", "normal", "spell-out", "digits", "literal-punctuation", "no-punctuation"
  26965. ],
  26966. "text-line-through": [
  26967. "none", "dotted", "dashed", "solid", "double", "dot-dash", "dot-dot-dash", "wave", "continuous",
  26968. "skip-white-space"
  26969. ],
  26970. "color-rendering": [
  26971. "auto", "optimizeSpeed", "optimizeQuality"
  26972. ],
  26973. "list-style-type": [
  26974. "none", "disc", "circle", "square", "decimal", "decimal-leading-zero", "arabic-indic", "binary", "bengali",
  26975. "cambodian", "khmer", "devanagari", "gujarati", "gurmukhi", "kannada", "lower-hexadecimal", "lao", "malayalam",
  26976. "mongolian", "myanmar", "octal", "oriya", "persian", "urdu", "telugu", "tibetan", "thai", "upper-hexadecimal",
  26977. "lower-roman", "upper-roman", "lower-greek", "lower-alpha", "lower-latin", "upper-alpha", "upper-latin", "afar",
  26978. "ethiopic-halehame-aa-et", "ethiopic-halehame-aa-er", "amharic", "ethiopic-halehame-am-et", "amharic-abegede",
  26979. "ethiopic-abegede-am-et", "cjk-earthly-branch", "cjk-heavenly-stem", "ethiopic", "ethiopic-halehame-gez",
  26980. "ethiopic-abegede", "ethiopic-abegede-gez", "hangul-consonant", "hangul", "lower-norwegian", "oromo",
  26981. "ethiopic-halehame-om-et", "sidama", "ethiopic-halehame-sid-et", "somali", "ethiopic-halehame-so-et", "tigre",
  26982. "ethiopic-halehame-tig", "tigrinya-er", "ethiopic-halehame-ti-er", "tigrinya-er-abegede",
  26983. "ethiopic-abegede-ti-er", "tigrinya-et", "ethiopic-halehame-ti-et", "tigrinya-et-abegede",
  26984. "ethiopic-abegede-ti-et", "upper-greek", "upper-norwegian", "asterisks", "footnotes", "hebrew", "armenian",
  26985. "lower-armenian", "upper-armenian", "georgian", "cjk-ideographic", "hiragana", "katakana", "hiragana-iroha",
  26986. "katakana-iroha"
  26987. ],
  26988. "-webkit-text-combine": [
  26989. "none", "horizontal"
  26990. ],
  26991. "outline": [
  26992. "none", "hidden", "inset", "groove", "ridge", "outset", "dotted", "dashed", "solid", "double"
  26993. ],
  26994. "font": [
  26995. "caption", "icon", "menu", "message-box", "small-caption", "-webkit-mini-control", "-webkit-small-control",
  26996. "-webkit-control", "status-bar", "italic", "oblique", "small-caps", "normal", "bold", "bolder", "lighter",
  26997. "100", "200", "300", "400", "500", "600", "700", "800", "900", "xx-small", "x-small", "small", "medium",
  26998. "large", "x-large", "xx-large", "-webkit-xxx-large", "smaller", "larger", "serif", "sans-serif", "cursive",
  26999. "fantasy", "monospace", "-webkit-body", "-webkit-pictograph"
  27000. ],
  27001. "dominant-baseline": [
  27002. "middle", "auto", "central", "text-before-edge", "text-after-edge", "ideographic", "alphabetic", "hanging",
  27003. "mathematical", "use-script", "no-change", "reset-size"
  27004. ],
  27005. "display": [
  27006. "none", "inline", "block", "list-item", "run-in", "compact", "inline-block", "table", "inline-table",
  27007. "table-row-group", "table-header-group", "table-footer-group", "table-row", "table-column-group",
  27008. "table-column", "table-cell", "table-caption", "-webkit-box", "-webkit-inline-box", "-wap-marquee"
  27009. ],
  27010. "-webkit-text-emphasis-position": [
  27011. "over", "under"
  27012. ],
  27013. "image-rendering": [
  27014. "auto", "optimizeSpeed", "optimizeQuality"
  27015. ],
  27016. "alignment-baseline": [
  27017. "baseline", "middle", "auto", "before-edge", "after-edge", "central", "text-before-edge", "text-after-edge",
  27018. "ideographic", "alphabetic", "hanging", "mathematical"
  27019. ],
  27020. "outline-width": [
  27021. "medium", "thick", "thin"
  27022. ],
  27023. "text-line-through-width": [
  27024. "normal", "medium", "auto", "thick", "thin"
  27025. ],
  27026. "box-align": [
  27027. "baseline", "center", "stretch", "start", "end"
  27028. ],
  27029. "border-right-width": [
  27030. "medium", "thick", "thin"
  27031. ],
  27032. "border-top-style": [
  27033. "none", "hidden", "inset", "groove", "ridge", "outset", "dotted", "dashed", "solid", "double"
  27034. ],
  27035. "line-height": [
  27036. "normal"
  27037. ],
  27038. "text-overflow": [
  27039. "clip", "ellipsis"
  27040. ],
  27041. "box-direction": [
  27042. "normal", "reverse"
  27043. ],
  27044. "margin-after-collapse": [
  27045. "collapse", "separate", "discard"
  27046. ],
  27047. "page-break-before": [
  27048. "left", "right", "auto", "always", "avoid"
  27049. ],
  27050. "-webkit-hyphens": [
  27051. "none", "auto", "manual"
  27052. ],
  27053. "border-image": [
  27054. "repeat", "stretch"
  27055. ],
  27056. "text-decoration": [
  27057. "blink", "line-through", "overline", "underline"
  27058. ],
  27059. "position": [
  27060. "absolute", "fixed", "relative", "static"
  27061. ],
  27062. "font-family": [
  27063. "serif", "sans-serif", "cursive", "fantasy", "monospace", "-webkit-body", "-webkit-pictograph"
  27064. ],
  27065. "text-overflow-mode": [
  27066. "clip", "ellipsis"
  27067. ],
  27068. "border-bottom-style": [
  27069. "none", "hidden", "inset", "groove", "ridge", "outset", "dotted", "dashed", "solid", "double"
  27070. ],
  27071. "unicode-bidi": [
  27072. "normal", "bidi-override", "embed"
  27073. ],
  27074. "clip-rule": [
  27075. "nonzero", "evenodd"
  27076. ],
  27077. "margin-left": [
  27078. "auto"
  27079. ],
  27080. "margin-top": [
  27081. "auto"
  27082. ],
  27083. "zoom": [
  27084. "document", "reset"
  27085. ],
  27086. "text-overline-style": [
  27087. "none", "dotted", "dashed", "solid", "double", "dot-dash", "dot-dot-dash", "wave"
  27088. ],
  27089. "max-width": [
  27090. "none"
  27091. ],
  27092. "empty-cells": [
  27093. "hide", "show"
  27094. ],
  27095. "pointer-events": [
  27096. "none", "all", "auto", "visible", "visiblepainted", "visiblefill", "visiblestroke", "painted", "fill", "stroke"
  27097. ],
  27098. "letter-spacing": [
  27099. "normal"
  27100. ],
  27101. "background-clip": [
  27102. "border-box", "content-box", "padding-box"
  27103. ],
  27104. "-webkit-font-smoothing": [
  27105. "none", "auto", "antialiased", "subpixel-antialiased"
  27106. ],
  27107. "border": [
  27108. "none", "hidden", "inset", "groove", "ridge", "outset", "dotted", "dashed", "solid", "double"
  27109. ],
  27110. "font-size": [
  27111. "xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large", "-webkit-xxx-large", "smaller",
  27112. "larger"
  27113. ],
  27114. "font-variant": [
  27115. "small-caps", "normal"
  27116. ],
  27117. "vertical-align": [
  27118. "baseline", "middle", "sub", "super", "text-top", "text-bottom", "top", "bottom", "-webkit-baseline-middle"
  27119. ],
  27120. "marquee-style": [
  27121. "none", "scroll", "slide", "alternate"
  27122. ],
  27123. "white-space": [
  27124. "normal", "nowrap", "pre", "pre-line", "pre-wrap"
  27125. ],
  27126. "text-underline-width": [
  27127. "normal", "medium", "auto", "thick", "thin"
  27128. ],
  27129. "box-lines": [
  27130. "single", "multiple"
  27131. ],
  27132. "page-break-after": [
  27133. "left", "right", "auto", "always", "avoid"
  27134. ],
  27135. "clip-path": [
  27136. "none"
  27137. ],
  27138. "margin": [
  27139. "auto"
  27140. ],
  27141. "marquee-repetition": [
  27142. "infinite"
  27143. ],
  27144. "margin-right": [
  27145. "auto"
  27146. ],
  27147. "-webkit-text-emphasis-style": [
  27148. "circle", "filled", "open", "dot", "double-circle", "triangle", "sesame"
  27149. ],
  27150. "-webkit-transform": [
  27151. "scale", "scaleX", "scaleY", "scale3d", "rotate", "rotateX", "rotateY", "rotateZ", "rotate3d", "skew", "skewX", "skewY", 
  27152. "translate", "translateX", "translateY", "translateZ", "translate3d", "matrix", "matrix3d", "perspective"
  27153. ]
  27154. }
  27155.  
  27156.  
  27157.  
  27158.  
  27159.  
  27160.  
  27161. WebInspector.PanelEnablerView = function(identifier, headingText, disclaimerText, buttonTitle)
  27162. {
  27163. WebInspector.View.call(this);
  27164. this.registerRequiredCSS("panelEnablerView.css");
  27165.  
  27166. this.element.addStyleClass("panel-enabler-view");
  27167. this.element.addStyleClass(identifier);
  27168.  
  27169. this.contentElement = document.createElement("div");
  27170. this.contentElement.className = "panel-enabler-view-content";
  27171. this.element.appendChild(this.contentElement);
  27172.  
  27173. this.imageElement = document.createElement("img");
  27174. this.contentElement.appendChild(this.imageElement);
  27175.  
  27176. this.choicesForm = document.createElement("form");
  27177. this.contentElement.appendChild(this.choicesForm);
  27178.  
  27179. this.headerElement = document.createElement("h1");
  27180. this.headerElement.textContent = headingText;
  27181. this.choicesForm.appendChild(this.headerElement);
  27182.  
  27183. var self = this;
  27184. function enableOption(text, checked) {
  27185. var label = document.createElement("label");
  27186. var option = document.createElement("input");
  27187. option.type = "radio";
  27188. option.name = "enable-option";
  27189. if (checked)
  27190. option.checked = true;
  27191. label.appendChild(option);
  27192. label.appendChild(document.createTextNode(text));
  27193. self.choicesForm.appendChild(label);
  27194. return option;
  27195. };
  27196.  
  27197. this.enabledForSession = enableOption(WebInspector.UIString("Only enable for this session"), true);
  27198. this.enabledAlways = enableOption(WebInspector.UIString("Always enable"), false);
  27199.  
  27200. this.disclaimerElement = document.createElement("div");
  27201. this.disclaimerElement.className = "panel-enabler-disclaimer";
  27202. this.disclaimerElement.textContent = disclaimerText;
  27203. this.choicesForm.appendChild(this.disclaimerElement);
  27204.  
  27205. this.enableButton = document.createElement("button");
  27206. this.enableButton.setAttribute("type", "button");
  27207. this.enableButton.textContent = buttonTitle;
  27208. this.enableButton.addEventListener("click", this._enableButtonCicked.bind(this), false);
  27209. this.choicesForm.appendChild(this.enableButton);
  27210. }
  27211.  
  27212. WebInspector.PanelEnablerView.prototype = {
  27213. _enableButtonCicked: function()
  27214. {
  27215. this.dispatchEventToListeners("enable clicked");
  27216. },
  27217.  
  27218. onResize: function()
  27219. {
  27220. this.imageElement.removeStyleClass("hidden");
  27221.  
  27222. if (this.element.offsetWidth < (this.choicesForm.offsetWidth + this.imageElement.offsetWidth))
  27223. this.imageElement.addStyleClass("hidden");
  27224. },
  27225.  
  27226. get alwaysEnabled() {
  27227. return this.enabledAlways.checked;
  27228. },
  27229.  
  27230. __proto__: WebInspector.View.prototype
  27231. }
  27232.  
  27233.  
  27234.  
  27235.  
  27236.  
  27237.  
  27238. WebInspector.StatusBarItem = function(element)
  27239. {
  27240. this.element = element;
  27241. this._enabled = true;
  27242. }
  27243.  
  27244. WebInspector.StatusBarItem.prototype = {
  27245.  
  27246. setEnabled: function(value)
  27247. {
  27248. if (this._enabled === value)
  27249. return;
  27250. this._enabled = value;
  27251. this._applyEnabledState();
  27252. },
  27253.  
  27254.  
  27255. _applyEnabledState: function()
  27256. {
  27257. this.element.disabled = !this._enabled;
  27258. },
  27259.  
  27260. __proto__: WebInspector.Object.prototype
  27261. }
  27262.  
  27263.  
  27264. WebInspector.StatusBarButton = function(title, className, states)
  27265. {
  27266. WebInspector.StatusBarItem.call(this, document.createElement("button"));
  27267. this.element.className = className + " status-bar-item";
  27268. this.element.addEventListener("click", this._clicked.bind(this), false);
  27269.  
  27270. this.glyph = document.createElement("div");
  27271. this.glyph.className = "glyph";
  27272. this.element.appendChild(this.glyph);
  27273.  
  27274. this.glyphShadow = document.createElement("div");
  27275. this.glyphShadow.className = "glyph shadow";
  27276. this.element.appendChild(this.glyphShadow);
  27277.  
  27278. this.states = states;
  27279. if (!states)
  27280. this.states = 2;
  27281.  
  27282. if (states == 2)
  27283. this._state = false;
  27284. else
  27285. this._state = 0;
  27286.  
  27287. this.title = title;
  27288. this.className = className;
  27289. this._visible = true;
  27290. }
  27291.  
  27292. WebInspector.StatusBarButton.width = 31;
  27293.  
  27294. WebInspector.StatusBarButton.prototype = {
  27295. _clicked: function()
  27296. {
  27297. this.dispatchEventToListeners("click");
  27298. if (this._showOptionsTimer)
  27299. clearTimeout(this._showOptionsTimer);
  27300. },
  27301.  
  27302.  
  27303. enabled: function()
  27304. {
  27305. return this._enabled;
  27306. },
  27307.  
  27308. get title()
  27309. {
  27310. return this._title;
  27311. },
  27312.  
  27313. set title(x)
  27314. {
  27315. if (this._title === x)
  27316. return;
  27317. this._title = x;
  27318. this.element.title = x;
  27319. },
  27320.  
  27321. get state()
  27322. {
  27323. return this._state;
  27324. },
  27325.  
  27326. set state(x)
  27327. {
  27328. if (this._state === x)
  27329. return;
  27330.  
  27331. if (this.states === 2) {
  27332. if (x)
  27333. this.element.addStyleClass("toggled-on");
  27334. else
  27335. this.element.removeStyleClass("toggled-on");
  27336. } else {
  27337. if (x !== 0) {
  27338. this.element.removeStyleClass("toggled-" + this._state);
  27339. this.element.addStyleClass("toggled-" + x);
  27340. } else
  27341. this.element.removeStyleClass("toggled-" + this._state);
  27342. }
  27343. this._state = x;
  27344. },
  27345.  
  27346. get toggled()
  27347. {
  27348. if (this.states !== 2)
  27349. throw("Only used toggled when there are 2 states, otherwise, use state");
  27350. return this.state;
  27351. },
  27352.  
  27353. set toggled(x)
  27354. {
  27355. if (this.states !== 2)
  27356. throw("Only used toggled when there are 2 states, otherwise, use state");
  27357. this.state = x;
  27358. },
  27359.  
  27360. get visible()
  27361. {
  27362. return this._visible;
  27363. },
  27364.  
  27365. set visible(x)
  27366. {
  27367. if (this._visible === x)
  27368. return;
  27369.  
  27370. if (x)
  27371. this.element.removeStyleClass("hidden");
  27372. else
  27373. this.element.addStyleClass("hidden");
  27374. this._visible = x;
  27375. },
  27376.  
  27377.  
  27378. makeLongClickEnabled: function(buttonsProvider)
  27379. {
  27380. this.longClickGlyph = document.createElement("div");
  27381. this.longClickGlyph.className = "fill long-click-glyph";
  27382. this.element.appendChild(this.longClickGlyph);
  27383.  
  27384. this.longClickGlyphShadow = document.createElement("div");
  27385. this.longClickGlyphShadow.className = "fill long-click-glyph shadow";
  27386. this.element.appendChild(this.longClickGlyphShadow);
  27387.  
  27388. this.element.addEventListener("mousedown", mouseDown.bind(this), false);
  27389. this.element.addEventListener("mouseout", mouseUp.bind(this), false);
  27390. this.element.addEventListener("mouseup", mouseUp.bind(this), false);
  27391.  
  27392. function mouseDown(e)
  27393. {
  27394. if (e.which !== 1)
  27395. return;
  27396. this._showOptionsTimer = setTimeout(this._showOptions.bind(this, buttonsProvider), 200);
  27397. }
  27398.  
  27399. function mouseUp(e)
  27400. {
  27401. if (e.which !== 1)
  27402. return;
  27403. if (this._showOptionsTimer)
  27404. clearTimeout(this._showOptionsTimer);
  27405. }
  27406. },
  27407.  
  27408.  
  27409. _showOptions: function(buttonsProvider)
  27410. {
  27411. var buttons = buttonsProvider();
  27412. var mainButtonClone = new WebInspector.StatusBarButton(this.title, this.className, this.states);
  27413. mainButtonClone.addEventListener("click", this._clicked, this);
  27414. mainButtonClone.state = this.state;
  27415. buttons.push(mainButtonClone);
  27416.  
  27417. var mouseUpListener = mouseUp.bind(this);
  27418. document.documentElement.addEventListener("mouseup", mouseUpListener, false);
  27419.  
  27420. var optionsGlassPane = new WebInspector.GlassPane();
  27421. var optionsBarElement = optionsGlassPane.element.createChild("div", "alternate-status-bar-buttons-bar");
  27422. const buttonHeight = 24;
  27423. optionsBarElement.style.height = (buttonHeight * buttons.length) + "px";
  27424. optionsBarElement.style.left = (this.element.offsetLeft + 1) + "px";
  27425.  
  27426. var boundMouseOver = mouseOver.bind(this);
  27427. var boundMouseOut = mouseOut.bind(this);
  27428. for (var i = 0; i < buttons.length; ++i) {
  27429. buttons[i].element.addEventListener("mousemove", boundMouseOver, false);
  27430. buttons[i].element.addEventListener("mouseout", boundMouseOut, false);
  27431. optionsBarElement.appendChild(buttons[i].element);
  27432. }
  27433. buttons[buttons.length - 1].element.addStyleClass("emulate-active");
  27434.  
  27435. function mouseOver(e)
  27436. {
  27437. if (e.which !== 1)
  27438. return;
  27439. var buttonElement = e.target.enclosingNodeOrSelfWithClass("status-bar-item");
  27440. buttonElement.addStyleClass("emulate-active");
  27441. }
  27442.  
  27443. function mouseOut(e)
  27444. {
  27445. if (e.which !== 1)
  27446. return;
  27447. var buttonElement = e.target.enclosingNodeOrSelfWithClass("status-bar-item");
  27448. buttonElement.removeStyleClass("emulate-active");
  27449. }
  27450.  
  27451. function mouseUp(e)
  27452. {
  27453. if (e.which !== 1)
  27454. return;
  27455. optionsGlassPane.dispose();
  27456. document.documentElement.removeEventListener("mouseup", mouseUpListener, false);
  27457.  
  27458. for (var i = 0; i < buttons.length; ++i) {
  27459. if (buttons[i].element.hasStyleClass("emulate-active"))
  27460. buttons[i]._clicked();
  27461. }
  27462. }
  27463. },
  27464.  
  27465. __proto__: WebInspector.StatusBarItem.prototype
  27466. }
  27467.  
  27468.  
  27469. WebInspector.StatusBarComboBox = function(changeHandler, className)
  27470. {
  27471. WebInspector.StatusBarItem.call(this, document.createElement("span"));
  27472. this.element.className = "status-bar-select-container";
  27473.  
  27474. this._selectElement = this.element.createChild("select", "status-bar-item");
  27475. if (changeHandler)
  27476. this._selectElement.addEventListener("change", changeHandler, false);
  27477. if (className)
  27478. this._selectElement.addStyleClass(className);
  27479. }
  27480.  
  27481. WebInspector.StatusBarComboBox.prototype = {
  27482.  
  27483. addOption: function(option)
  27484. {
  27485. this._selectElement.appendChild(option);
  27486. },
  27487.  
  27488.  
  27489. _applyEnabledState: function()
  27490. {
  27491. this._selectElement.disabled = !this._enabled;
  27492. },
  27493.  
  27494.  
  27495. removeOption: function(option)
  27496. {
  27497. this._selectElement.removeChild(option);
  27498. },
  27499.  
  27500. removeOptions: function()
  27501. {
  27502. this._selectElement.removeChildren();
  27503. },
  27504.  
  27505.  
  27506. selectedOption: function()
  27507. {
  27508. if (this._selectElement.selectedIndex >= 0)
  27509. return this._selectElement[this._selectElement.selectedIndex];
  27510. return null;
  27511. },
  27512.  
  27513.  
  27514. select: function(option)
  27515. {
  27516. this._selectElement.selectedIndex = Array.prototype.indexOf.call(this._selectElement, option);
  27517. },
  27518.  
  27519. __proto__: WebInspector.StatusBarItem.prototype
  27520. }
  27521.  
  27522.  
  27523.  
  27524.  
  27525.  
  27526.  
  27527. WebInspector.TextEditor = function() { };
  27528.  
  27529. WebInspector.TextEditor.Events = {
  27530. GutterClick: "gutterClick"
  27531. };
  27532.  
  27533. WebInspector.TextEditor.prototype = {
  27534.  
  27535.  
  27536. set mimeType(mimeType) { },
  27537.  
  27538.  
  27539. setReadOnly: function(readOnly) { },
  27540.  
  27541.  
  27542. readOnly: function() { },
  27543.  
  27544.  
  27545. defaultFocusedElement: function() { },
  27546.  
  27547.  
  27548. revealLine: function(lineNumber) { },
  27549.  
  27550.  
  27551. addBreakpoint: function(lineNumber, disabled, conditional) { },
  27552.  
  27553.  
  27554. removeBreakpoint: function(lineNumber) { },
  27555.  
  27556.  
  27557. setExecutionLine: function(lineNumber) { },
  27558.  
  27559. clearExecutionLine: function() { },
  27560.  
  27561.  
  27562. addDecoration: function(lineNumber, element) { },
  27563.  
  27564.  
  27565. removeDecoration: function(lineNumber, element) { },
  27566.  
  27567.  
  27568. markAndRevealRange: function(range) { },
  27569.  
  27570.  
  27571. highlightLine: function(lineNumber) { },
  27572.  
  27573. clearLineHighlight: function() { },
  27574.  
  27575.  
  27576. elementsToRestoreScrollPositionsFor: function() { },
  27577.  
  27578.  
  27579. inheritScrollPositions: function(textEditor) { },
  27580.  
  27581. beginUpdates: function() { },
  27582.  
  27583. endUpdates: function() { },
  27584.  
  27585. onResize: function() { },
  27586.  
  27587.  
  27588. editRange: function(range, text) { },
  27589.  
  27590.  
  27591. scrollToLine: function(lineNumber) { },
  27592.  
  27593.  
  27594. selection: function(textRange) { },
  27595.  
  27596.  
  27597. lastSelection: function() { },
  27598.  
  27599.  
  27600. setSelection: function(textRange) { },
  27601.  
  27602.  
  27603. setText: function(text) { },
  27604.  
  27605.  
  27606. text: function() { },
  27607.  
  27608.  
  27609. range: function() { },
  27610.  
  27611.  
  27612. line: function(lineNumber) { },
  27613.  
  27614.  
  27615. get linesCount() { },
  27616.  
  27617.  
  27618. setAttribute: function(line, name, value) { },
  27619.  
  27620.  
  27621. getAttribute: function(line, name) { },
  27622.  
  27623.  
  27624. removeAttribute: function(line, name) { },
  27625.  
  27626. wasShown: function() { },
  27627.  
  27628. willHide: function() { }
  27629. }
  27630.  
  27631.  
  27632. WebInspector.TextEditorDelegate = function()
  27633. {
  27634. }
  27635.  
  27636. WebInspector.TextEditorDelegate.prototype = {
  27637.  
  27638. onTextChanged: function(oldRange, newRange) { },
  27639.  
  27640.  
  27641. selectionChanged: function(textRange) { },
  27642.  
  27643.  
  27644. scrollChanged: function(lineNumber) { },
  27645.  
  27646.  
  27647. populateLineGutterContextMenu: function(contextMenu, lineNumber) { },
  27648.  
  27649.  
  27650. populateTextAreaContextMenu: function(contextMenu, lineNumber) { },
  27651.  
  27652.  
  27653. createLink: function(hrefValue, isExternal) { }
  27654. }
  27655.  
  27656.  
  27657.  
  27658.  
  27659.  
  27660.  
  27661. WebInspector.DefaultTextEditor = function(url, delegate)
  27662. {
  27663. WebInspector.View.call(this);
  27664. this._delegate = delegate;
  27665. this._url = url;
  27666.  
  27667. this.registerRequiredCSS("textEditor.css");
  27668.  
  27669. this.element.className = "text-editor monospace";
  27670.  
  27671.  
  27672. this.element.addEventListener("mouseup", preventDefaultOnMouseUp.bind(this), false);
  27673. function preventDefaultOnMouseUp(event)
  27674. {
  27675. if (event.button === 1)
  27676. event.consume(true);
  27677. }
  27678.  
  27679. this._textModel = new WebInspector.TextEditorModel();
  27680. this._textModel.addEventListener(WebInspector.TextEditorModel.Events.TextChanged, this._textChanged, this);
  27681.  
  27682. var syncScrollListener = this._syncScroll.bind(this);
  27683. var syncDecorationsForLineListener = this._syncDecorationsForLine.bind(this);
  27684. var syncLineHeightListener = this._syncLineHeight.bind(this);
  27685. this._mainPanel = new WebInspector.TextEditorMainPanel(this._delegate, this._textModel, url, syncScrollListener, syncDecorationsForLineListener);
  27686. this._gutterPanel = new WebInspector.TextEditorGutterPanel(this._textModel, syncDecorationsForLineListener, syncLineHeightListener);
  27687.  
  27688. this._mainPanel.element.addEventListener("scroll", this._handleScrollChanged.bind(this), false);
  27689. this._mainPanel._container.addEventListener("focus", this._handleFocused.bind(this), false);
  27690.  
  27691. this._gutterPanel.element.addEventListener("mousedown", this._onMouseDown.bind(this), true);
  27692.  
  27693.  
  27694. this._mainPanel.element.addEventListener("mouseup", consumeMouseUp.bind(this), false);
  27695. function consumeMouseUp(event)
  27696. {
  27697. if (event.button === 1)
  27698. event.consume(false);
  27699. }
  27700.  
  27701. this.element.appendChild(this._mainPanel.element);
  27702. this.element.appendChild(this._gutterPanel.element);
  27703.  
  27704.  
  27705. function forwardWheelEvent(event)
  27706. {
  27707. var clone = document.createEvent("WheelEvent");
  27708. clone.initWebKitWheelEvent(event.wheelDeltaX, event.wheelDeltaY,
  27709. event.view,
  27710. event.screenX, event.screenY,
  27711. event.clientX, event.clientY,
  27712. event.ctrlKey, event.altKey, event.shiftKey, event.metaKey);
  27713. this._mainPanel.element.dispatchEvent(clone);
  27714. }
  27715. this._gutterPanel.element.addEventListener("mousewheel", forwardWheelEvent.bind(this), false);
  27716.  
  27717. this.element.addEventListener("keydown", this._handleKeyDown.bind(this), false);
  27718. this.element.addEventListener("cut", this._handleCut.bind(this), false);
  27719. this.element.addEventListener("textInput", this._handleTextInput.bind(this), false);
  27720. this.element.addEventListener("contextmenu", this._contextMenu.bind(this), true);
  27721.  
  27722. this._registerShortcuts();
  27723. }
  27724.  
  27725.  
  27726. WebInspector.DefaultTextEditor.EditInfo = function(range, text)
  27727. {
  27728. this.range = range;
  27729. this.text = text;
  27730. }
  27731.  
  27732. WebInspector.DefaultTextEditor.prototype = {
  27733.  
  27734. set mimeType(mimeType)
  27735. {
  27736. this._mainPanel.mimeType = mimeType;
  27737. },
  27738.  
  27739.  
  27740. setReadOnly: function(readOnly)
  27741. {
  27742. if (this._mainPanel.readOnly() === readOnly)
  27743. return;
  27744. this._mainPanel.setReadOnly(readOnly, this.isShowing());
  27745. WebInspector.markBeingEdited(this.element, !readOnly);
  27746. },
  27747.  
  27748.  
  27749. readOnly: function()
  27750. {
  27751. return this._mainPanel.readOnly();
  27752. },
  27753.  
  27754.  
  27755. defaultFocusedElement: function()
  27756. {
  27757. return this._mainPanel.defaultFocusedElement();
  27758. },
  27759.  
  27760.  
  27761. revealLine: function(lineNumber)
  27762. {
  27763. this._mainPanel.revealLine(lineNumber);
  27764. },
  27765.  
  27766. _onMouseDown: function(event)
  27767. {
  27768. var target = event.target.enclosingNodeOrSelfWithClass("webkit-line-number");
  27769. if (!target)
  27770. return;
  27771. this.dispatchEventToListeners(WebInspector.TextEditor.Events.GutterClick, { lineNumber: target.lineNumber, event: event });
  27772. },
  27773.  
  27774.  
  27775. addBreakpoint: function(lineNumber, disabled, conditional)
  27776. {
  27777. this.beginUpdates();
  27778. this._gutterPanel.addDecoration(lineNumber, "webkit-breakpoint");
  27779. if (disabled)
  27780. this._gutterPanel.addDecoration(lineNumber, "webkit-breakpoint-disabled");
  27781. else
  27782. this._gutterPanel.removeDecoration(lineNumber, "webkit-breakpoint-disabled");
  27783. if (conditional)
  27784. this._gutterPanel.addDecoration(lineNumber, "webkit-breakpoint-conditional");
  27785. else
  27786. this._gutterPanel.removeDecoration(lineNumber, "webkit-breakpoint-conditional");
  27787. this.endUpdates();
  27788. },
  27789.  
  27790.  
  27791. removeBreakpoint: function(lineNumber)
  27792. {
  27793. this.beginUpdates();
  27794. this._gutterPanel.removeDecoration(lineNumber, "webkit-breakpoint");
  27795. this._gutterPanel.removeDecoration(lineNumber, "webkit-breakpoint-disabled");
  27796. this._gutterPanel.removeDecoration(lineNumber, "webkit-breakpoint-conditional");
  27797. this.endUpdates();
  27798. },
  27799.  
  27800.  
  27801. setExecutionLine: function(lineNumber)
  27802. {
  27803. this._executionLineNumber = lineNumber;
  27804. this._mainPanel.addDecoration(lineNumber, "webkit-execution-line");
  27805. this._gutterPanel.addDecoration(lineNumber, "webkit-execution-line");
  27806. },
  27807.  
  27808. clearExecutionLine: function()
  27809. {
  27810. if (typeof this._executionLineNumber === "number") {
  27811. this._mainPanel.removeDecoration(this._executionLineNumber, "webkit-execution-line");
  27812. this._gutterPanel.removeDecoration(this._executionLineNumber, "webkit-execution-line");
  27813. }
  27814. delete this._executionLineNumber;
  27815. },
  27816.  
  27817.  
  27818. addDecoration: function(lineNumber, element)
  27819. {
  27820. this._mainPanel.addDecoration(lineNumber, element);
  27821. this._gutterPanel.addDecoration(lineNumber, element);
  27822. this._syncDecorationsForLine(lineNumber);
  27823. },
  27824.  
  27825.  
  27826. removeDecoration: function(lineNumber, element)
  27827. {
  27828. this._mainPanel.removeDecoration(lineNumber, element);
  27829. this._gutterPanel.removeDecoration(lineNumber, element);
  27830. this._syncDecorationsForLine(lineNumber);
  27831. },
  27832.  
  27833.  
  27834. markAndRevealRange: function(range)
  27835. {
  27836. if (range)
  27837. this.setSelection(range);
  27838. this._mainPanel.markAndRevealRange(range);
  27839. },
  27840.  
  27841.  
  27842. highlightLine: function(lineNumber)
  27843. {
  27844. if (typeof lineNumber !== "number" || lineNumber < 0)
  27845. return;
  27846.  
  27847. lineNumber = Math.min(lineNumber, this._textModel.linesCount - 1);
  27848. this._mainPanel.highlightLine(lineNumber);
  27849. },
  27850.  
  27851. clearLineHighlight: function()
  27852. {
  27853. this._mainPanel.clearLineHighlight();
  27854. },
  27855.  
  27856. _freeCachedElements: function()
  27857. {
  27858. this._mainPanel._freeCachedElements();
  27859. this._gutterPanel._freeCachedElements();
  27860. },
  27861.  
  27862.  
  27863. elementsToRestoreScrollPositionsFor: function()
  27864. {
  27865. return [this._mainPanel.element];
  27866. },
  27867.  
  27868.  
  27869. inheritScrollPositions: function(textEditor)
  27870. {
  27871. this._mainPanel.element._scrollTop = textEditor._mainPanel.element.scrollTop;
  27872. this._mainPanel.element._scrollLeft = textEditor._mainPanel.element.scrollLeft;
  27873. },
  27874.  
  27875. beginUpdates: function()
  27876. {
  27877. this._mainPanel.beginUpdates();
  27878. this._gutterPanel.beginUpdates();
  27879. },
  27880.  
  27881. endUpdates: function()
  27882. {
  27883. this._mainPanel.endUpdates();
  27884. this._gutterPanel.endUpdates();
  27885. this._updatePanelOffsets();
  27886. },
  27887.  
  27888. onResize: function()
  27889. {
  27890. this._mainPanel.resize();
  27891. this._gutterPanel.resize();
  27892. this._updatePanelOffsets();
  27893. },
  27894.  
  27895. _textChanged: function(event)
  27896. {
  27897. this._mainPanel.textChanged(event.data.oldRange, event.data.newRange);
  27898. this._gutterPanel.textChanged(event.data.oldRange, event.data.newRange);
  27899. this._updatePanelOffsets();
  27900. if (event.data.editRange)
  27901. this._delegate.onTextChanged(event.data.oldRange, event.data.newRange);
  27902. },
  27903.  
  27904.  
  27905. editRange: function(range, text)
  27906. {
  27907. return this._textModel.editRange(range, text);
  27908. },
  27909.  
  27910. _updatePanelOffsets: function()
  27911. {
  27912. var lineNumbersWidth = this._gutterPanel.element.offsetWidth;
  27913. if (lineNumbersWidth)
  27914. this._mainPanel.element.style.setProperty("left", (lineNumbersWidth + 2) + "px");
  27915. else
  27916. this._mainPanel.element.style.removeProperty("left"); 
  27917. },
  27918.  
  27919. _syncScroll: function()
  27920. {
  27921. var mainElement = this._mainPanel.element;
  27922. var gutterElement = this._gutterPanel.element;
  27923.  
  27924. this._gutterPanel.syncClientHeight(mainElement.clientHeight);
  27925. gutterElement.scrollTop = mainElement.scrollTop;
  27926. },
  27927.  
  27928.  
  27929. _syncDecorationsForLine: function(lineNumber)
  27930. {
  27931. if (lineNumber >= this._textModel.linesCount)
  27932. return;
  27933.  
  27934. var mainChunk = this._mainPanel.chunkForLine(lineNumber);
  27935. if (mainChunk.linesCount === 1 && mainChunk.isDecorated()) {
  27936. var gutterChunk = this._gutterPanel.makeLineAChunk(lineNumber);
  27937. var height = mainChunk.height;
  27938. if (height)
  27939. gutterChunk.element.style.setProperty("height", height + "px");
  27940. else
  27941. gutterChunk.element.style.removeProperty("height");
  27942. } else {
  27943. var gutterChunk = this._gutterPanel.chunkForLine(lineNumber);
  27944. if (gutterChunk.linesCount === 1)
  27945. gutterChunk.element.style.removeProperty("height");
  27946. }
  27947. },
  27948.  
  27949.  
  27950. _syncLineHeight: function(gutterRow)
  27951. {
  27952. if (this._lineHeightSynced)
  27953. return;
  27954. if (gutterRow && gutterRow.offsetHeight) {
  27955.  
  27956. this.element.style.setProperty("line-height", gutterRow.offsetHeight + "px");
  27957. this._lineHeightSynced = true;
  27958. }
  27959. },
  27960.  
  27961. _registerShortcuts: function()
  27962. {
  27963. var keys = WebInspector.KeyboardShortcut.Keys;
  27964. var modifiers = WebInspector.KeyboardShortcut.Modifiers;
  27965.  
  27966. this._shortcuts = {};
  27967.  
  27968. var handleEnterKey = this._mainPanel.handleEnterKey.bind(this._mainPanel);
  27969. this._shortcuts[WebInspector.KeyboardShortcut.makeKey(keys.Enter.code, WebInspector.KeyboardShortcut.Modifiers.None)] = handleEnterKey;
  27970.  
  27971. this._shortcuts[WebInspector.KeyboardShortcut.makeKey("z", modifiers.CtrlOrMeta)] = this._mainPanel.handleUndoRedo.bind(this._mainPanel, false);
  27972. this._shortcuts[WebInspector.KeyboardShortcut.SelectAll] = this._handleSelectAll.bind(this);
  27973.  
  27974. var handleRedo = this._mainPanel.handleUndoRedo.bind(this._mainPanel, true);
  27975. this._shortcuts[WebInspector.KeyboardShortcut.makeKey("z", modifiers.Shift | modifiers.CtrlOrMeta)] = handleRedo;
  27976. if (!WebInspector.isMac())
  27977. this._shortcuts[WebInspector.KeyboardShortcut.makeKey("y", modifiers.CtrlOrMeta)] = handleRedo;
  27978.  
  27979. var handleTabKey = this._mainPanel.handleTabKeyPress.bind(this._mainPanel, false);
  27980. var handleShiftTabKey = this._mainPanel.handleTabKeyPress.bind(this._mainPanel, true);
  27981. this._shortcuts[WebInspector.KeyboardShortcut.makeKey(keys.Tab.code)] = handleTabKey;
  27982. this._shortcuts[WebInspector.KeyboardShortcut.makeKey(keys.Tab.code, modifiers.Shift)] = handleShiftTabKey;
  27983. },
  27984.  
  27985. _handleSelectAll: function()
  27986. {
  27987. this.setSelection(this._textModel.range());
  27988. return true;
  27989. },
  27990.  
  27991. _handleTextInput: function(e)
  27992. {
  27993. this._mainPanel._textInputData = e.data;
  27994. },
  27995.  
  27996. _handleKeyDown: function(e)
  27997. {
  27998.  
  27999.  
  28000. if (e.target.enclosingNodeOrSelfWithClass("webkit-line-decorations"))
  28001. return;
  28002.  
  28003. var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(e);
  28004.  
  28005. var handler = this._shortcuts[shortcutKey];
  28006. if (handler && handler()) {
  28007. e.consume(true);
  28008. return;
  28009. }
  28010. this._mainPanel._keyDownCode = e.keyCode;
  28011. },
  28012.  
  28013. _handleCut: function(e)
  28014. {
  28015. this._mainPanel._keyDownCode = WebInspector.KeyboardShortcut.Keys.Delete.code;
  28016. },
  28017.  
  28018. _contextMenu: function(event)
  28019. {
  28020. var anchor = event.target.enclosingNodeOrSelfWithNodeName("a");
  28021. if (anchor)
  28022. return;
  28023. var contextMenu = new WebInspector.ContextMenu(event);
  28024. var target = event.target.enclosingNodeOrSelfWithClass("webkit-line-number");
  28025. if (target)
  28026. this._delegate.populateLineGutterContextMenu(contextMenu, target.lineNumber);
  28027. else {
  28028. target = this._mainPanel._enclosingLineRowOrSelf(event.target);
  28029. this._delegate.populateTextAreaContextMenu(contextMenu, target && target.lineNumber);
  28030. }
  28031. contextMenu.show();
  28032. },
  28033.  
  28034. _handleScrollChanged: function(event)
  28035. {
  28036. var visibleFrom = this._mainPanel._scrollTop();
  28037. var firstVisibleLineNumber = this._mainPanel._findFirstVisibleLineNumber(visibleFrom);
  28038. this._delegate.scrollChanged(firstVisibleLineNumber);
  28039. },
  28040.  
  28041.  
  28042. scrollToLine: function(lineNumber)
  28043. {
  28044. this._mainPanel.scrollToLine(lineNumber);
  28045. },
  28046.  
  28047.  
  28048. selection: function(textRange)
  28049. {
  28050. return this._mainPanel._getSelection();
  28051. },
  28052.  
  28053.  
  28054. lastSelection: function()
  28055. {
  28056. return this._mainPanel._lastSelection;
  28057. },
  28058.  
  28059.  
  28060. setSelection: function(textRange)
  28061. {
  28062. this._mainPanel._lastSelection = textRange;
  28063. if (this.element.isAncestor(document.activeElement))
  28064. this._mainPanel._restoreSelection(textRange);
  28065. },
  28066.  
  28067.  
  28068. setText: function(text)
  28069. {
  28070. this._textModel.setText(text);
  28071. },
  28072.  
  28073.  
  28074. text: function()
  28075. {
  28076. return this._textModel.text();
  28077. },
  28078.  
  28079.  
  28080. range: function()
  28081. {
  28082. return this._textModel.range();
  28083. },
  28084.  
  28085.  
  28086. line: function(lineNumber)
  28087. {
  28088. return this._textModel.line(lineNumber);
  28089. },
  28090.  
  28091.  
  28092. get linesCount()
  28093. {
  28094. return this._textModel.linesCount;
  28095. },
  28096.  
  28097.  
  28098. setAttribute: function(line, name, value)
  28099. {
  28100. this._textModel.setAttribute(line, name, value);
  28101. },
  28102.  
  28103.  
  28104. getAttribute: function(line, name)
  28105. {
  28106. return this._textModel.getAttribute(line, name);
  28107. },
  28108.  
  28109.  
  28110. removeAttribute: function(line, name)
  28111. {
  28112. this._textModel.removeAttribute(line, name);
  28113. },
  28114.  
  28115. wasShown: function()
  28116. {
  28117. if (!this.readOnly())
  28118. WebInspector.markBeingEdited(this.element, true);
  28119.  
  28120. this._boundSelectionChangeListener = this._mainPanel._handleSelectionChange.bind(this._mainPanel);
  28121. document.addEventListener("selectionchange", this._boundSelectionChangeListener, false);
  28122. this._mainPanel._wasShown();
  28123. },
  28124.  
  28125. _handleFocused: function()
  28126. {
  28127. if (this._mainPanel._lastSelection)
  28128. this.setSelection(this._mainPanel._lastSelection);
  28129. },
  28130.  
  28131. willHide: function()
  28132. {
  28133. this._mainPanel._willHide();
  28134. document.removeEventListener("selectionchange", this._boundSelectionChangeListener, false);
  28135. delete this._boundSelectionChangeListener;
  28136.  
  28137. if (!this.readOnly())
  28138. WebInspector.markBeingEdited(this.element, false);
  28139. this._freeCachedElements();
  28140. },
  28141.  
  28142.  
  28143. highlightRangesWithStyleClass: function(element, resultRanges, styleClass, changes)
  28144. {
  28145. this._mainPanel.beginDomUpdates();
  28146. WebInspector.highlightRangesWithStyleClass(element, resultRanges, styleClass, changes);
  28147. this._mainPanel.endDomUpdates();
  28148. },
  28149.  
  28150.  
  28151. highlightExpression: function(element, skipClasses, skipTokens)
  28152. {
  28153.  
  28154. var tokens = [ element ];
  28155. var token = element.previousSibling;
  28156. while (token && (skipClasses[token.className] || skipTokens[token.textContent.trim()])) {
  28157. tokens.push(token);
  28158. token = token.previousSibling;
  28159. }
  28160. tokens.reverse();
  28161.  
  28162.  
  28163. this._mainPanel.beginDomUpdates();
  28164. var parentElement = element.parentElement;
  28165. var nextElement = element.nextSibling;
  28166. var container = document.createElement("span");
  28167. for (var i = 0; i < tokens.length; ++i)
  28168. container.appendChild(tokens[i]);
  28169. parentElement.insertBefore(container, nextElement);
  28170. this._mainPanel.endDomUpdates();
  28171. return container;
  28172. },
  28173.  
  28174.  
  28175. hideHighlightedExpression: function(highlightElement)
  28176. {
  28177. this._mainPanel.beginDomUpdates();
  28178. var parentElement = highlightElement.parentElement;
  28179. if (parentElement) {
  28180. var child = highlightElement.firstChild;
  28181. while (child) {
  28182. var nextSibling = child.nextSibling;
  28183. parentElement.insertBefore(child, highlightElement);
  28184. child = nextSibling;
  28185. }
  28186. parentElement.removeChild(highlightElement);
  28187. }
  28188. this._mainPanel.endDomUpdates();
  28189. },
  28190.  
  28191.  
  28192. overrideViewportForTest: function(scrollTop, clientHeight, chunkSize)
  28193. {
  28194. this._mainPanel._scrollTopOverrideForTest = scrollTop;
  28195. this._mainPanel._clientHeightOverrideForTest = clientHeight;
  28196. this._mainPanel._defaultChunkSize = chunkSize;
  28197. },
  28198.  
  28199. __proto__: WebInspector.View.prototype
  28200. }
  28201.  
  28202.  
  28203. WebInspector.TextEditorChunkedPanel = function(textModel)
  28204. {
  28205. this._textModel = textModel;
  28206.  
  28207. this._defaultChunkSize = 50;
  28208. this._paintCoalescingLevel = 0;
  28209. this._domUpdateCoalescingLevel = 0;
  28210. }
  28211.  
  28212. WebInspector.TextEditorChunkedPanel.prototype = {
  28213.  
  28214. scrollToLine: function(lineNumber)
  28215. {
  28216. if (lineNumber >= this._textModel.linesCount)
  28217. return;
  28218.  
  28219. var chunk = this.makeLineAChunk(lineNumber);
  28220. this.element.scrollTop = chunk.offsetTop;
  28221. },
  28222.  
  28223.  
  28224. revealLine: function(lineNumber)
  28225. {
  28226. if (lineNumber >= this._textModel.linesCount)
  28227. return;
  28228.  
  28229. var chunk = this.makeLineAChunk(lineNumber);
  28230. chunk.element.scrollIntoViewIfNeeded();
  28231. },
  28232.  
  28233.  
  28234. addDecoration: function(lineNumber, decoration)
  28235. {
  28236. if (lineNumber >= this._textModel.linesCount)
  28237. return;
  28238.  
  28239. var chunk = this.makeLineAChunk(lineNumber);
  28240. chunk.addDecoration(decoration);
  28241. },
  28242.  
  28243.  
  28244. removeDecoration: function(lineNumber, decoration)
  28245. {
  28246. if (lineNumber >= this._textModel.linesCount)
  28247. return;
  28248.  
  28249. var chunk = this.chunkForLine(lineNumber);
  28250. chunk.removeDecoration(decoration);
  28251. },
  28252.  
  28253. _buildChunks: function()
  28254. {
  28255. this.beginDomUpdates();
  28256.  
  28257. this._container.removeChildren();
  28258.  
  28259. this._textChunks = [];
  28260. for (var i = 0; i < this._textModel.linesCount; i += this._defaultChunkSize) {
  28261. var chunk = this._createNewChunk(i, i + this._defaultChunkSize);
  28262. this._textChunks.push(chunk);
  28263. this._container.appendChild(chunk.element);
  28264. }
  28265.  
  28266. this._repaintAll();
  28267.  
  28268. this.endDomUpdates();
  28269. },
  28270.  
  28271.  
  28272. makeLineAChunk: function(lineNumber)
  28273. {
  28274. var chunkNumber = this._chunkNumberForLine(lineNumber);
  28275. var oldChunk = this._textChunks[chunkNumber];
  28276.  
  28277. if (!oldChunk) {
  28278. console.error("No chunk for line number: " + lineNumber);
  28279. return;
  28280. }
  28281.  
  28282. if (oldChunk.linesCount === 1)
  28283. return oldChunk;
  28284.  
  28285. return this._splitChunkOnALine(lineNumber, chunkNumber, true);
  28286. },
  28287.  
  28288.  
  28289. _splitChunkOnALine: function(lineNumber, chunkNumber, createSuffixChunk)
  28290. {
  28291. this.beginDomUpdates();
  28292.  
  28293. var oldChunk = this._textChunks[chunkNumber];
  28294. var wasExpanded = oldChunk.expanded;
  28295. oldChunk.expanded = false;
  28296.  
  28297. var insertIndex = chunkNumber + 1;
  28298.  
  28299.  
  28300. if (lineNumber > oldChunk.startLine) {
  28301. var prefixChunk = this._createNewChunk(oldChunk.startLine, lineNumber);
  28302. this._textChunks.splice(insertIndex++, 0, prefixChunk);
  28303. this._container.insertBefore(prefixChunk.element, oldChunk.element);
  28304. }
  28305.  
  28306.  
  28307. var endLine = createSuffixChunk ? lineNumber + 1 : oldChunk.startLine + oldChunk.linesCount;
  28308. var lineChunk = this._createNewChunk(lineNumber, endLine);
  28309. this._textChunks.splice(insertIndex++, 0, lineChunk);
  28310. this._container.insertBefore(lineChunk.element, oldChunk.element);
  28311.  
  28312.  
  28313. if (oldChunk.startLine + oldChunk.linesCount > endLine) {
  28314. var suffixChunk = this._createNewChunk(endLine, oldChunk.startLine + oldChunk.linesCount);
  28315. this._textChunks.splice(insertIndex, 0, suffixChunk);
  28316. this._container.insertBefore(suffixChunk.element, oldChunk.element);
  28317. }
  28318.  
  28319.  
  28320. this._textChunks.splice(chunkNumber, 1);
  28321. this._container.removeChild(oldChunk.element);
  28322.  
  28323. if (wasExpanded) {
  28324. if (prefixChunk)
  28325. prefixChunk.expanded = true;
  28326. lineChunk.expanded = true;
  28327. if (suffixChunk)
  28328. suffixChunk.expanded = true;
  28329. }
  28330.  
  28331. this.endDomUpdates();
  28332.  
  28333. return lineChunk;
  28334. },
  28335.  
  28336. _scroll: function()
  28337. {
  28338. this._scheduleRepaintAll();
  28339. if (this._syncScrollListener)
  28340. this._syncScrollListener();
  28341. },
  28342.  
  28343. _scheduleRepaintAll: function()
  28344. {
  28345. if (this._repaintAllTimer)
  28346. clearTimeout(this._repaintAllTimer);
  28347. this._repaintAllTimer = setTimeout(this._repaintAll.bind(this), 50);
  28348. },
  28349.  
  28350. beginUpdates: function()
  28351. {
  28352. this._paintCoalescingLevel++;
  28353. },
  28354.  
  28355. endUpdates: function()
  28356. {
  28357. this._paintCoalescingLevel--;
  28358. if (!this._paintCoalescingLevel)
  28359. this._repaintAll();
  28360. },
  28361.  
  28362. beginDomUpdates: function()
  28363. {
  28364. this._domUpdateCoalescingLevel++;
  28365. },
  28366.  
  28367. endDomUpdates: function()
  28368. {
  28369. this._domUpdateCoalescingLevel--;
  28370. },
  28371.  
  28372.  
  28373. _chunkNumberForLine: function(lineNumber)
  28374. {
  28375. function compareLineNumbers(value, chunk)
  28376. {
  28377. return value < chunk.startLine ? -1 : 1;
  28378. }
  28379. var insertBefore = insertionIndexForObjectInListSortedByFunction(lineNumber, this._textChunks, compareLineNumbers);
  28380. return insertBefore - 1;
  28381. },
  28382.  
  28383.  
  28384. chunkForLine: function(lineNumber)
  28385. {
  28386. return this._textChunks[this._chunkNumberForLine(lineNumber)];
  28387. },
  28388.  
  28389.  
  28390. _findFirstVisibleChunkNumber: function(visibleFrom)
  28391. {
  28392. function compareOffsetTops(value, chunk)
  28393. {
  28394. return value < chunk.offsetTop ? -1 : 1;
  28395. }
  28396. var insertBefore = insertionIndexForObjectInListSortedByFunction(visibleFrom, this._textChunks, compareOffsetTops);
  28397. return insertBefore - 1;
  28398. },
  28399.  
  28400.  
  28401. _findVisibleChunks: function(visibleFrom, visibleTo)
  28402. {
  28403. var from = this._findFirstVisibleChunkNumber(visibleFrom);
  28404. for (var to = from + 1; to < this._textChunks.length; ++to) {
  28405. if (this._textChunks[to].offsetTop >= visibleTo)
  28406. break;
  28407. }
  28408. return { start: from, end: to };
  28409. },
  28410.  
  28411.  
  28412. _findFirstVisibleLineNumber: function(visibleFrom)
  28413. {
  28414. var chunk = this._textChunks[this._findFirstVisibleChunkNumber(visibleFrom)];
  28415. if (!chunk.expanded)
  28416. return chunk.startLine;
  28417.  
  28418. var lineNumbers = [];
  28419. for (var i = 0; i < chunk.linesCount; ++i) {
  28420. lineNumbers.push(chunk.startLine + i);
  28421. }
  28422.  
  28423. function compareLineRowOffsetTops(value, lineNumber)
  28424. {
  28425. var lineRow = chunk.expandedLineRow(lineNumber);
  28426. return value < lineRow.offsetTop ? -1 : 1;
  28427. }
  28428. var insertBefore = insertionIndexForObjectInListSortedByFunction(visibleFrom, lineNumbers, compareLineRowOffsetTops);
  28429. return lineNumbers[insertBefore - 1];
  28430. },
  28431.  
  28432. _repaintAll: function()
  28433. {
  28434. delete this._repaintAllTimer;
  28435.  
  28436. if (this._paintCoalescingLevel)
  28437. return;
  28438.  
  28439. var visibleFrom = this._scrollTop();
  28440. var visibleTo = visibleFrom + this._clientHeight();
  28441.  
  28442. if (visibleTo) {
  28443. var result = this._findVisibleChunks(visibleFrom, visibleTo);
  28444. this._expandChunks(result.start, result.end);
  28445. }
  28446. },
  28447.  
  28448. _scrollTop: function()
  28449. {
  28450. return typeof this._scrollTopOverrideForTest === "number" ? this._scrollTopOverrideForTest : this.element.scrollTop; 
  28451. },
  28452.  
  28453. _clientHeight: function()
  28454. {
  28455. return typeof this._clientHeightOverrideForTest === "number" ? this._clientHeightOverrideForTest : this.element.clientHeight; 
  28456. },
  28457.  
  28458.  
  28459. _expandChunks: function(fromIndex, toIndex)
  28460. {
  28461.  
  28462. for (var i = 0; i < fromIndex; ++i)
  28463. this._textChunks[i].expanded = false;
  28464. for (var i = toIndex; i < this._textChunks.length; ++i)
  28465. this._textChunks[i].expanded = false;
  28466. for (var i = fromIndex; i < toIndex; ++i)
  28467. this._textChunks[i].expanded = true;
  28468. },
  28469.  
  28470.  
  28471. _totalHeight: function(firstElement, lastElement)
  28472. {
  28473. lastElement = (lastElement || firstElement).nextElementSibling;
  28474. if (lastElement)
  28475. return lastElement.offsetTop - firstElement.offsetTop;
  28476.  
  28477. var offsetParent = firstElement.offsetParent;
  28478. if (offsetParent && offsetParent.scrollHeight > offsetParent.clientHeight)
  28479. return offsetParent.scrollHeight - firstElement.offsetTop;
  28480.  
  28481. var total = 0;
  28482. while (firstElement && firstElement !== lastElement) {
  28483. total += firstElement.offsetHeight;
  28484. firstElement = firstElement.nextElementSibling;
  28485. }
  28486. return total;
  28487. },
  28488.  
  28489. resize: function()
  28490. {
  28491. this._repaintAll();
  28492. }
  28493. }
  28494.  
  28495.  
  28496. WebInspector.TextEditorGutterPanel = function(textModel, syncDecorationsForLineListener, syncLineHeightListener)
  28497. {
  28498. WebInspector.TextEditorChunkedPanel.call(this, textModel);
  28499.  
  28500. this._syncDecorationsForLineListener = syncDecorationsForLineListener;
  28501. this._syncLineHeightListener = syncLineHeightListener;
  28502.  
  28503. this.element = document.createElement("div");
  28504. this.element.className = "text-editor-lines";
  28505.  
  28506. this._container = document.createElement("div");
  28507. this._container.className = "inner-container";
  28508. this.element.appendChild(this._container);
  28509.  
  28510. this.element.addEventListener("scroll", this._scroll.bind(this), false);
  28511.  
  28512. this._freeCachedElements();
  28513. this._buildChunks();
  28514. this._decorations = {};
  28515. }
  28516.  
  28517. WebInspector.TextEditorGutterPanel.prototype = {
  28518. _freeCachedElements: function()
  28519. {
  28520. this._cachedRows = [];
  28521. },
  28522.  
  28523.  
  28524. _createNewChunk: function(startLine, endLine)
  28525. {
  28526. return new WebInspector.TextEditorGutterChunk(this, startLine, endLine);
  28527. },
  28528.  
  28529.  
  28530. textChanged: function(oldRange, newRange)
  28531. {
  28532. this.beginDomUpdates();
  28533.  
  28534. var linesDiff = newRange.linesCount - oldRange.linesCount;
  28535. if (linesDiff) {
  28536.  
  28537. for (var chunkNumber = this._textChunks.length - 1; chunkNumber >= 0 ; --chunkNumber) {
  28538. var chunk = this._textChunks[chunkNumber];
  28539. if (chunk.startLine + chunk.linesCount <= this._textModel.linesCount)
  28540. break;
  28541. chunk.expanded = false;
  28542. this._container.removeChild(chunk.element);
  28543. }
  28544. this._textChunks.length = chunkNumber + 1;
  28545.  
  28546.  
  28547. var totalLines = 0;
  28548. if (this._textChunks.length) {
  28549. var lastChunk = this._textChunks[this._textChunks.length - 1];
  28550. totalLines = lastChunk.startLine + lastChunk.linesCount;
  28551. }
  28552.  
  28553. for (var i = totalLines; i < this._textModel.linesCount; i += this._defaultChunkSize) {
  28554. var chunk = this._createNewChunk(i, i + this._defaultChunkSize);
  28555. this._textChunks.push(chunk);
  28556. this._container.appendChild(chunk.element);
  28557. }
  28558.  
  28559.  
  28560. for (var lineNumber in this._decorations) {
  28561. lineNumber = parseInt(lineNumber, 10);
  28562.  
  28563.  
  28564. if (lineNumber < oldRange.startLine)
  28565. continue;
  28566.  
  28567. if (lineNumber === oldRange.startLine && oldRange.startColumn)
  28568. continue;
  28569.  
  28570. var lineDecorationsCopy = this._decorations[lineNumber].slice();
  28571. for (var i = 0; i < lineDecorationsCopy.length; ++i) {
  28572. var decoration = lineDecorationsCopy[i];
  28573. this.removeDecoration(lineNumber, decoration);
  28574.  
  28575.  
  28576. if (lineNumber < oldRange.endLine)
  28577. continue;
  28578.  
  28579. this.addDecoration(lineNumber + linesDiff, decoration);
  28580. }
  28581. }
  28582.  
  28583. this._repaintAll();
  28584. } else {
  28585.  
  28586. var chunkNumber = this._chunkNumberForLine(newRange.startLine);
  28587. var chunk = this._textChunks[chunkNumber];
  28588. while (chunk && chunk.startLine <= newRange.endLine) {
  28589. if (chunk.linesCount === 1)
  28590. this._syncDecorationsForLineListener(chunk.startLine);
  28591. chunk = this._textChunks[++chunkNumber];
  28592. }
  28593. }
  28594.  
  28595. this.endDomUpdates();
  28596. },
  28597.  
  28598.  
  28599. syncClientHeight: function(clientHeight)
  28600. {
  28601. if (this.element.offsetHeight > clientHeight)
  28602. this._container.style.setProperty("padding-bottom", (this.element.offsetHeight - clientHeight) + "px");
  28603. else
  28604. this._container.style.removeProperty("padding-bottom");
  28605. },
  28606.  
  28607.  
  28608. addDecoration: function(lineNumber, decoration)
  28609. {
  28610. WebInspector.TextEditorChunkedPanel.prototype.addDecoration.call(this, lineNumber, decoration);
  28611. var decorations = this._decorations[lineNumber];
  28612. if (!decorations) {
  28613. decorations = [];
  28614. this._decorations[lineNumber] = decorations;
  28615. }
  28616. decorations.push(decoration);
  28617. },
  28618.  
  28619.  
  28620. removeDecoration: function(lineNumber, decoration)
  28621. {
  28622. WebInspector.TextEditorChunkedPanel.prototype.removeDecoration.call(this, lineNumber, decoration);
  28623. var decorations = this._decorations[lineNumber];
  28624. if (decorations) {
  28625. decorations.remove(decoration);
  28626. if (!decorations.length)
  28627. delete this._decorations[lineNumber];
  28628. }
  28629. },
  28630.  
  28631. __proto__: WebInspector.TextEditorChunkedPanel.prototype
  28632. }
  28633.  
  28634.  
  28635. WebInspector.TextEditorGutterChunk = function(textEditor, startLine, endLine)
  28636. {
  28637. this._textEditor = textEditor;
  28638. this._textModel = textEditor._textModel;
  28639.  
  28640. this.startLine = startLine;
  28641. endLine = Math.min(this._textModel.linesCount, endLine);
  28642. this.linesCount = endLine - startLine;
  28643.  
  28644. this._expanded = false;
  28645.  
  28646. this.element = document.createElement("div");
  28647. this.element.lineNumber = startLine;
  28648. this.element.className = "webkit-line-number";
  28649.  
  28650. if (this.linesCount === 1) {
  28651.  
  28652.  
  28653. var innerSpan = document.createElement("span");
  28654. innerSpan.className = "webkit-line-number-inner";
  28655. innerSpan.textContent = startLine + 1;
  28656. var outerSpan = document.createElement("div");
  28657. outerSpan.className = "webkit-line-number-outer";
  28658. outerSpan.appendChild(innerSpan);
  28659. this.element.appendChild(outerSpan);
  28660. } else {
  28661. var lineNumbers = [];
  28662. for (var i = startLine; i < endLine; ++i)
  28663. lineNumbers.push(i + 1);
  28664. this.element.textContent = lineNumbers.join("\n");
  28665. }
  28666. }
  28667.  
  28668. WebInspector.TextEditorGutterChunk.prototype = {
  28669.  
  28670. addDecoration: function(decoration)
  28671. {
  28672. this._textEditor.beginDomUpdates();
  28673. if (typeof decoration === "string")
  28674. this.element.addStyleClass(decoration);
  28675. this._textEditor.endDomUpdates();
  28676. },
  28677.  
  28678.  
  28679. removeDecoration: function(decoration)
  28680. {
  28681. this._textEditor.beginDomUpdates();
  28682. if (typeof decoration === "string")
  28683. this.element.removeStyleClass(decoration);
  28684. this._textEditor.endDomUpdates();
  28685. },
  28686.  
  28687.  
  28688. get expanded()
  28689. {
  28690. return this._expanded;
  28691. },
  28692.  
  28693. set expanded(expanded)
  28694. {
  28695. if (this.linesCount === 1)
  28696. this._textEditor._syncDecorationsForLineListener(this.startLine);
  28697.  
  28698. if (this._expanded === expanded)
  28699. return;
  28700.  
  28701. this._expanded = expanded;
  28702.  
  28703. if (this.linesCount === 1)
  28704. return;
  28705.  
  28706. this._textEditor.beginDomUpdates();
  28707.  
  28708. if (expanded) {
  28709. this._expandedLineRows = [];
  28710. var parentElement = this.element.parentElement;
  28711. for (var i = this.startLine; i < this.startLine + this.linesCount; ++i) {
  28712. var lineRow = this._createRow(i);
  28713. parentElement.insertBefore(lineRow, this.element);
  28714. this._expandedLineRows.push(lineRow);
  28715. }
  28716. parentElement.removeChild(this.element);
  28717. this._textEditor._syncLineHeightListener(this._expandedLineRows[0]);
  28718. } else {
  28719. var elementInserted = false;
  28720. for (var i = 0; i < this._expandedLineRows.length; ++i) {
  28721. var lineRow = this._expandedLineRows[i];
  28722. var parentElement = lineRow.parentElement;
  28723. if (parentElement) {
  28724. if (!elementInserted) {
  28725. elementInserted = true;
  28726. parentElement.insertBefore(this.element, lineRow);
  28727. }
  28728. parentElement.removeChild(lineRow);
  28729. }
  28730. this._textEditor._cachedRows.push(lineRow);
  28731. }
  28732. delete this._expandedLineRows;
  28733. }
  28734.  
  28735. this._textEditor.endDomUpdates();
  28736. },
  28737.  
  28738.  
  28739. get height()
  28740. {
  28741. if (!this._expandedLineRows)
  28742. return this._textEditor._totalHeight(this.element);
  28743. return this._textEditor._totalHeight(this._expandedLineRows[0], this._expandedLineRows[this._expandedLineRows.length - 1]);
  28744. },
  28745.  
  28746.  
  28747. get offsetTop()
  28748. {
  28749. return (this._expandedLineRows && this._expandedLineRows.length) ? this._expandedLineRows[0].offsetTop : this.element.offsetTop;
  28750. },
  28751.  
  28752.  
  28753. _createRow: function(lineNumber)
  28754. {
  28755. var lineRow = this._textEditor._cachedRows.pop() || document.createElement("div");
  28756. lineRow.lineNumber = lineNumber;
  28757. lineRow.className = "webkit-line-number";
  28758. lineRow.textContent = lineNumber + 1;
  28759. return lineRow;
  28760. }
  28761. }
  28762.  
  28763.  
  28764. WebInspector.TextEditorMainPanel = function(delegate, textModel, url, syncScrollListener, syncDecorationsForLineListener)
  28765. {
  28766. WebInspector.TextEditorChunkedPanel.call(this, textModel);
  28767.  
  28768. this._delegate = delegate;
  28769. this._syncScrollListener = syncScrollListener;
  28770. this._syncDecorationsForLineListener = syncDecorationsForLineListener;
  28771.  
  28772. this._url = url;
  28773. this._highlighter = new WebInspector.TextEditorHighlighter(textModel, this._highlightDataReady.bind(this));
  28774. this._readOnly = true;
  28775.  
  28776. this.element = document.createElement("div");
  28777. this.element.className = "text-editor-contents";
  28778. this.element.tabIndex = 0;
  28779.  
  28780. this._container = document.createElement("div");
  28781. this._container.className = "inner-container";
  28782. this._container.tabIndex = 0;
  28783. this.element.appendChild(this._container);
  28784.  
  28785. this.element.addEventListener("scroll", this._scroll.bind(this), false);
  28786. this.element.addEventListener("focus", this._handleElementFocus.bind(this), false);
  28787.  
  28788. this._freeCachedElements();
  28789. this._buildChunks();
  28790. }
  28791.  
  28792. WebInspector.TextEditorMainPanel.prototype = {
  28793. _wasShown: function()
  28794. {
  28795. this._isShowing = true;
  28796. this._attachMutationObserver();
  28797. },
  28798.  
  28799. _willHide: function()
  28800. {
  28801. this._detachMutationObserver();
  28802. this._isShowing = false;
  28803. },
  28804.  
  28805. _attachMutationObserver: function()
  28806. {
  28807. if (!this._isShowing)
  28808. return;
  28809.  
  28810. if (this._mutationObserver)
  28811. this._mutationObserver.disconnect();
  28812. this._mutationObserver = new NonLeakingMutationObserver(this._handleMutations.bind(this));
  28813. this._mutationObserver.observe(this._container, { subtree: true, childList: true, characterData: true });
  28814. },
  28815.  
  28816. _detachMutationObserver: function()
  28817. {
  28818. if (!this._isShowing)
  28819. return;
  28820.  
  28821. if (this._mutationObserver) {
  28822. this._mutationObserver.disconnect();
  28823. delete this._mutationObserver;
  28824. }
  28825. },
  28826.  
  28827.  
  28828. set mimeType(mimeType)
  28829. {
  28830. this._highlighter.mimeType = mimeType;
  28831. },
  28832.  
  28833.  
  28834. setReadOnly: function(readOnly, requestFocus)
  28835. {
  28836. if (this._readOnly === readOnly)
  28837. return;
  28838.  
  28839. this.beginDomUpdates();
  28840. this._readOnly = readOnly;
  28841. if (this._readOnly)
  28842. this._container.removeStyleClass("text-editor-editable");
  28843. else {
  28844. this._container.addStyleClass("text-editor-editable");
  28845. if (requestFocus)
  28846. this._updateSelectionOnStartEditing();
  28847. }
  28848. this.endDomUpdates();
  28849. },
  28850.  
  28851.  
  28852. readOnly: function()
  28853. {
  28854. return this._readOnly;
  28855. },
  28856.  
  28857. _handleElementFocus: function()
  28858. {
  28859. if (!this._readOnly)
  28860. this._container.focus();
  28861. },
  28862.  
  28863.  
  28864. defaultFocusedElement: function()
  28865. {
  28866. if (this._readOnly)
  28867. return this.element;
  28868. return this._container;
  28869. },
  28870.  
  28871. _updateSelectionOnStartEditing: function()
  28872. {
  28873.  
  28874.  
  28875.  
  28876.  
  28877. this._container.focus();
  28878. var selection = window.getSelection();
  28879. if (selection.rangeCount) {
  28880. var commonAncestorContainer = selection.getRangeAt(0).commonAncestorContainer;
  28881. if (this._container.isSelfOrAncestor(commonAncestorContainer))
  28882. return;
  28883. }
  28884.  
  28885. selection.removeAllRanges();
  28886. var range = document.createRange();
  28887. range.setStart(this._container, 0);
  28888. range.setEnd(this._container, 0);
  28889. selection.addRange(range);
  28890. },
  28891.  
  28892.  
  28893. markAndRevealRange: function(range)
  28894. {
  28895. if (this._rangeToMark) {
  28896. var markedLine = this._rangeToMark.startLine;
  28897. delete this._rangeToMark;
  28898.  
  28899. this.beginDomUpdates();
  28900. var chunk = this.chunkForLine(markedLine);
  28901. var wasExpanded = chunk.expanded;
  28902. chunk.expanded = false;
  28903. chunk.updateCollapsedLineRow();
  28904. chunk.expanded = wasExpanded;
  28905. this.endDomUpdates();
  28906. }
  28907.  
  28908. if (range) {
  28909. this._rangeToMark = range;
  28910. this.revealLine(range.startLine);
  28911. var chunk = this.makeLineAChunk(range.startLine);
  28912. this._paintLine(chunk.element);
  28913. if (this._markedRangeElement)
  28914. this._markedRangeElement.scrollIntoViewIfNeeded();
  28915. }
  28916. delete this._markedRangeElement;
  28917. },
  28918.  
  28919.  
  28920. highlightLine: function(lineNumber)
  28921. {
  28922. this.clearLineHighlight();
  28923. this._highlightedLine = lineNumber;
  28924. this.revealLine(lineNumber);
  28925.  
  28926. if (!this._readOnly)
  28927. this._restoreSelection(WebInspector.TextRange.createFromLocation(lineNumber, 0), false);
  28928.  
  28929. this.addDecoration(lineNumber, "webkit-highlighted-line");
  28930. },
  28931.  
  28932. clearLineHighlight: function()
  28933. {
  28934. if (typeof this._highlightedLine === "number") {
  28935. this.removeDecoration(this._highlightedLine, "webkit-highlighted-line");
  28936. delete this._highlightedLine;
  28937. }
  28938. },
  28939.  
  28940. _freeCachedElements: function()
  28941. {
  28942. this._cachedSpans = [];
  28943. this._cachedTextNodes = [];
  28944. this._cachedRows = [];
  28945. },
  28946.  
  28947.  
  28948. handleUndoRedo: function(redo)
  28949. {
  28950. if (this.readOnly())
  28951. return false;
  28952.  
  28953. this.beginUpdates();
  28954.  
  28955. var range = redo ? this._textModel.redo() : this._textModel.undo();
  28956.  
  28957. this.endUpdates();
  28958.  
  28959.  
  28960. if (range)
  28961. this._restoreSelection(range, true);
  28962.  
  28963. return true;
  28964. },
  28965.  
  28966.  
  28967. handleTabKeyPress: function(shiftKey)
  28968. {
  28969. if (this.readOnly())
  28970. return false;
  28971.  
  28972. var selection = this._getSelection();
  28973. if (!selection)
  28974. return false;
  28975.  
  28976. var range = selection.normalize();
  28977.  
  28978. this.beginUpdates();
  28979.  
  28980. var newRange;
  28981. var rangeWasEmpty = range.isEmpty();
  28982. if (shiftKey)
  28983. newRange = this._textModel.unindentLines(range);
  28984. else {
  28985. if (rangeWasEmpty)
  28986. newRange = this._textModel.editRange(range, WebInspector.settings.textEditorIndent.get());
  28987. else
  28988. newRange = this._textModel.indentLines(range);
  28989. }
  28990.  
  28991. this.endUpdates();
  28992. if (rangeWasEmpty)
  28993. newRange.startColumn = newRange.endColumn;
  28994. this._restoreSelection(newRange, true);
  28995. return true;
  28996. },
  28997.  
  28998. handleEnterKey: function()
  28999. {
  29000. if (this.readOnly())
  29001. return false;
  29002.  
  29003. var range = this._getSelection();
  29004. if (!range)
  29005. return false;
  29006.  
  29007. range = range.normalize();
  29008.  
  29009. if (range.endColumn === 0)
  29010. return false;
  29011.  
  29012. var line = this._textModel.line(range.startLine);
  29013. var linePrefix = line.substring(0, range.startColumn);
  29014. var indentMatch = linePrefix.match(/^\s+/);
  29015. var currentIndent = indentMatch ? indentMatch[0] : "";
  29016.  
  29017. var textEditorIndent = WebInspector.settings.textEditorIndent.get();
  29018. var indent = WebInspector.TextEditorModel.endsWithBracketRegex.test(linePrefix) ? currentIndent + textEditorIndent : currentIndent;
  29019.  
  29020. if (!indent)
  29021. return false;
  29022.  
  29023. this.beginDomUpdates();
  29024.  
  29025. var lineBreak = this._textModel.lineBreak;
  29026. var newRange;
  29027. if (range.isEmpty() && line.substr(range.endColumn - 1, 2) === '{}') {
  29028.  
  29029.  
  29030.  
  29031.  
  29032.  
  29033. newRange = this._textModel.editRange(range, lineBreak + indent + lineBreak + currentIndent);
  29034. newRange.endLine--;
  29035. newRange.endColumn += textEditorIndent.length;
  29036. } else
  29037. newRange = this._textModel.editRange(range, lineBreak + indent);
  29038.  
  29039. this.endDomUpdates();
  29040. this._restoreSelection(newRange.collapseToEnd(), true);
  29041.  
  29042. return true;
  29043. },
  29044.  
  29045.  
  29046. _splitChunkOnALine: function(lineNumber, chunkNumber, createSuffixChunk)
  29047. {
  29048. var selection = this._getSelection();
  29049. var chunk = WebInspector.TextEditorChunkedPanel.prototype._splitChunkOnALine.call(this, lineNumber, chunkNumber, createSuffixChunk);
  29050. this._restoreSelection(selection);
  29051. return chunk;
  29052. },
  29053.  
  29054. beginDomUpdates: function()
  29055. {
  29056. if (!this._domUpdateCoalescingLevel)
  29057. this._detachMutationObserver();
  29058. WebInspector.TextEditorChunkedPanel.prototype.beginDomUpdates.call(this);
  29059. },
  29060.  
  29061. endDomUpdates: function()
  29062. {
  29063. WebInspector.TextEditorChunkedPanel.prototype.endDomUpdates.call(this);
  29064. if (!this._domUpdateCoalescingLevel)
  29065. this._attachMutationObserver();
  29066. },
  29067.  
  29068. _buildChunks: function()
  29069. {
  29070. for (var i = 0; i < this._textModel.linesCount; ++i)
  29071. this._textModel.removeAttribute(i, "highlight");
  29072.  
  29073. WebInspector.TextEditorChunkedPanel.prototype._buildChunks.call(this);
  29074. },
  29075.  
  29076.  
  29077. _createNewChunk: function(startLine, endLine)
  29078. {
  29079. return new WebInspector.TextEditorMainChunk(this, startLine, endLine);
  29080. },
  29081.  
  29082.  
  29083. _expandChunks: function(fromIndex, toIndex)
  29084. {
  29085. var lastChunk = this._textChunks[toIndex - 1];
  29086. var lastVisibleLine = lastChunk.startLine + lastChunk.linesCount;
  29087.  
  29088. var selection = this._getSelection();
  29089.  
  29090. this._muteHighlightListener = true;
  29091. this._highlighter.highlight(lastVisibleLine);
  29092. delete this._muteHighlightListener;
  29093.  
  29094. this._restorePaintLinesOperationsCredit();
  29095. WebInspector.TextEditorChunkedPanel.prototype._expandChunks.call(this, fromIndex, toIndex);
  29096. this._adjustPaintLinesOperationsRefreshValue();
  29097.  
  29098. this._restoreSelection(selection);
  29099. },
  29100.  
  29101.  
  29102. _highlightDataReady: function(fromLine, toLine)
  29103. {
  29104. if (this._muteHighlightListener)
  29105. return;
  29106. this._restorePaintLinesOperationsCredit();
  29107. this._paintLines(fromLine, toLine, true  );
  29108. },
  29109.  
  29110.  
  29111. _schedulePaintLines: function(startLine, endLine)
  29112. {
  29113. if (startLine >= endLine)
  29114. return;
  29115.  
  29116. if (!this._scheduledPaintLines) {
  29117. this._scheduledPaintLines = [ { startLine: startLine, endLine: endLine } ];
  29118. this._paintScheduledLinesTimer = setTimeout(this._paintScheduledLines.bind(this), 0);
  29119. } else {
  29120. for (var i = 0; i < this._scheduledPaintLines.length; ++i) {
  29121. var chunk = this._scheduledPaintLines[i];
  29122. if (chunk.startLine <= endLine && chunk.endLine >= startLine) {
  29123. chunk.startLine = Math.min(chunk.startLine, startLine);
  29124. chunk.endLine = Math.max(chunk.endLine, endLine);
  29125. return;
  29126. }
  29127. if (chunk.startLine > endLine) {
  29128. this._scheduledPaintLines.splice(i, 0, { startLine: startLine, endLine: endLine });
  29129. return;
  29130. }
  29131. }
  29132. this._scheduledPaintLines.push({ startLine: startLine, endLine: endLine });
  29133. }
  29134. },
  29135.  
  29136.  
  29137. _paintScheduledLines: function(skipRestoreSelection)
  29138. {
  29139. if (this._paintScheduledLinesTimer)
  29140. clearTimeout(this._paintScheduledLinesTimer);
  29141. delete this._paintScheduledLinesTimer;
  29142.  
  29143. if (!this._scheduledPaintLines)
  29144. return;
  29145.  
  29146.  
  29147. if (this._repaintAllTimer) {
  29148. this._paintScheduledLinesTimer = setTimeout(this._paintScheduledLines.bind(this), 50);
  29149. return;
  29150. }
  29151.  
  29152. var scheduledPaintLines = this._scheduledPaintLines;
  29153. delete this._scheduledPaintLines;
  29154.  
  29155. this._restorePaintLinesOperationsCredit();
  29156. this._paintLineChunks(scheduledPaintLines, !skipRestoreSelection);
  29157. this._adjustPaintLinesOperationsRefreshValue();
  29158. },
  29159.  
  29160. _restorePaintLinesOperationsCredit: function()
  29161. {
  29162. if (!this._paintLinesOperationsRefreshValue)
  29163. this._paintLinesOperationsRefreshValue = 250;
  29164. this._paintLinesOperationsCredit = this._paintLinesOperationsRefreshValue;
  29165. this._paintLinesOperationsLastRefresh = Date.now();
  29166. },
  29167.  
  29168. _adjustPaintLinesOperationsRefreshValue: function()
  29169. {
  29170. var operationsDone = this._paintLinesOperationsRefreshValue - this._paintLinesOperationsCredit;
  29171. if (operationsDone <= 0)
  29172. return;
  29173. var timePast = Date.now() - this._paintLinesOperationsLastRefresh;
  29174. if (timePast <= 0)
  29175. return;
  29176.  
  29177. var value = Math.floor(operationsDone / timePast * 50);
  29178. this._paintLinesOperationsRefreshValue = Number.constrain(value, 150, 1500);
  29179. },
  29180.  
  29181.  
  29182. _paintLines: function(fromLine, toLine, restoreSelection)
  29183. {
  29184. this._paintLineChunks([ { startLine: fromLine, endLine: toLine } ], restoreSelection);
  29185. },
  29186.  
  29187.  
  29188. _paintLineChunks: function(lineChunks, restoreSelection)
  29189. {
  29190.  
  29191.  
  29192. var visibleFrom = this._scrollTop();
  29193. var firstVisibleLineNumber = this._findFirstVisibleLineNumber(visibleFrom);
  29194.  
  29195. var chunk;
  29196. var selection;
  29197. var invisibleLineRows = [];
  29198. for (var i = 0; i < lineChunks.length; ++i) {
  29199. var lineChunk = lineChunks[i];
  29200. if (this._scheduledPaintLines) {
  29201. this._schedulePaintLines(lineChunk.startLine, lineChunk.endLine);
  29202. continue;
  29203. }
  29204. for (var lineNumber = lineChunk.startLine; lineNumber < lineChunk.endLine; ++lineNumber) {
  29205. if (!chunk || lineNumber < chunk.startLine || lineNumber >= chunk.startLine + chunk.linesCount)
  29206. chunk = this.chunkForLine(lineNumber);
  29207. var lineRow = chunk.expandedLineRow(lineNumber);
  29208. if (!lineRow)
  29209. continue;
  29210. if (lineNumber < firstVisibleLineNumber) {
  29211. invisibleLineRows.push(lineRow);
  29212. continue;
  29213. }
  29214. if (restoreSelection && !selection)
  29215. selection = this._getSelection();
  29216. this._paintLine(lineRow);
  29217. if (this._paintLinesOperationsCredit < 0) {
  29218. this._schedulePaintLines(lineNumber + 1, lineChunk.endLine);
  29219. break;
  29220. }
  29221. }
  29222. }
  29223.  
  29224. for (var i = 0; i < invisibleLineRows.length; ++i) {
  29225. if (restoreSelection && !selection)
  29226. selection = this._getSelection();
  29227. this._paintLine(invisibleLineRows[i]);
  29228. }
  29229.  
  29230. if (restoreSelection)
  29231. this._restoreSelection(selection);
  29232. },
  29233.  
  29234.  
  29235. _paintLine: function(lineRow)
  29236. {
  29237. var lineNumber = lineRow.lineNumber;
  29238.  
  29239. this.beginDomUpdates();
  29240. try {
  29241. if (this._scheduledPaintLines || this._paintLinesOperationsCredit < 0) {
  29242. this._schedulePaintLines(lineNumber, lineNumber + 1);
  29243. return;
  29244. }
  29245.  
  29246. var highlight = this._textModel.getAttribute(lineNumber, "highlight");
  29247. if (!highlight)
  29248. return;
  29249.  
  29250. var decorationsElement = lineRow.decorationsElement;
  29251. if (!decorationsElement)
  29252. lineRow.removeChildren();
  29253. else {
  29254. while (true) {
  29255. var child = lineRow.firstChild;
  29256. if (!child || child === decorationsElement)
  29257. break;
  29258. lineRow.removeChild(child);
  29259. }
  29260. }
  29261.  
  29262. var line = this._textModel.line(lineNumber);
  29263. if (!line)
  29264. lineRow.insertBefore(document.createElement("br"), decorationsElement);
  29265.  
  29266. var plainTextStart = -1;
  29267. for (var j = 0; j < line.length;) {
  29268. if (j > 1000) {
  29269.  
  29270. if (plainTextStart === -1)
  29271. plainTextStart = j;
  29272. break;
  29273. }
  29274. var attribute = highlight[j];
  29275. if (!attribute || !attribute.tokenType) {
  29276. if (plainTextStart === -1)
  29277. plainTextStart = j;
  29278. j++;
  29279. } else {
  29280. if (plainTextStart !== -1) {
  29281. this._insertTextNodeBefore(lineRow, decorationsElement, line.substring(plainTextStart, j));
  29282. plainTextStart = -1;
  29283. --this._paintLinesOperationsCredit;
  29284. }
  29285. this._insertSpanBefore(lineRow, decorationsElement, line.substring(j, j + attribute.length), attribute.tokenType);
  29286. j += attribute.length;
  29287. --this._paintLinesOperationsCredit;
  29288. }
  29289. }
  29290. if (plainTextStart !== -1) {
  29291. this._insertTextNodeBefore(lineRow, decorationsElement, line.substring(plainTextStart, line.length));
  29292. --this._paintLinesOperationsCredit;
  29293. }
  29294. } finally {
  29295. if (this._rangeToMark && this._rangeToMark.startLine === lineNumber)
  29296. this._markedRangeElement = WebInspector.highlightSearchResult(lineRow, this._rangeToMark.startColumn, this._rangeToMark.endColumn - this._rangeToMark.startColumn);
  29297. this.endDomUpdates();
  29298. }
  29299. },
  29300.  
  29301.  
  29302. _releaseLinesHighlight: function(lineRow)
  29303. {
  29304. if (!lineRow)
  29305. return;
  29306. if ("spans" in lineRow) {
  29307. var spans = lineRow.spans;
  29308. for (var j = 0; j < spans.length; ++j)
  29309. this._cachedSpans.push(spans[j]);
  29310. delete lineRow.spans;
  29311. }
  29312. if ("textNodes" in lineRow) {
  29313. var textNodes = lineRow.textNodes;
  29314. for (var j = 0; j < textNodes.length; ++j)
  29315. this._cachedTextNodes.push(textNodes[j]);
  29316. delete lineRow.textNodes;
  29317. }
  29318. this._cachedRows.push(lineRow);
  29319. },
  29320.  
  29321.  
  29322. _getSelection: function(lastUndamagedLineRow)
  29323. {
  29324. var selection = window.getSelection();
  29325. if (!selection.rangeCount)
  29326. return null;
  29327.  
  29328. if (!this._container.isAncestor(selection.anchorNode) || !this._container.isAncestor(selection.focusNode))
  29329. return null;
  29330. var start = this._selectionToPosition(selection.anchorNode, selection.anchorOffset, lastUndamagedLineRow);
  29331. var end = selection.isCollapsed ? start : this._selectionToPosition(selection.focusNode, selection.focusOffset, lastUndamagedLineRow);
  29332. return new WebInspector.TextRange(start.line, start.column, end.line, end.column);
  29333. },
  29334.  
  29335.  
  29336. _restoreSelection: function(range, scrollIntoView)
  29337. {
  29338. if (!range)
  29339. return;
  29340.  
  29341. var start = this._positionToSelection(range.startLine, range.startColumn);
  29342. var end = range.isEmpty() ? start : this._positionToSelection(range.endLine, range.endColumn);
  29343. window.getSelection().setBaseAndExtent(start.container, start.offset, end.container, end.offset);
  29344.  
  29345. if (scrollIntoView) {
  29346. for (var node = end.container; node; node = node.parentElement) {
  29347. if (node.scrollIntoViewIfNeeded) {
  29348. node.scrollIntoViewIfNeeded();
  29349. break;
  29350. }
  29351. }
  29352. }
  29353. this._lastSelection = range;
  29354. },
  29355.  
  29356.  
  29357. _selectionToPosition: function(container, offset, lastUndamagedLineRow)
  29358. {
  29359. if (container === this._container && offset === 0)
  29360. return { line: 0, column: 0 };
  29361. if (container === this._container && offset === 1)
  29362. return { line: this._textModel.linesCount - 1, column: this._textModel.lineLength(this._textModel.linesCount - 1) };
  29363.  
  29364.  
  29365.  
  29366. var lineNumber;
  29367. var column = 0;
  29368. var node;
  29369. var scopeNode;
  29370. if (lastUndamagedLineRow === null) {
  29371.  
  29372. node = this._container.firstChild;
  29373. scopeNode = this._container;
  29374. lineNumber = 0;
  29375. } else {
  29376. var lineRow = this._enclosingLineRowOrSelf(container);
  29377. if (!lastUndamagedLineRow || (typeof lineRow.lineNumber === "number" && lineRow.lineNumber <= lastUndamagedLineRow.lineNumber)) {
  29378.  
  29379. node = lineRow;
  29380. scopeNode = node;
  29381. lineNumber = node.lineNumber;
  29382. } else {
  29383.  
  29384. node = lastUndamagedLineRow.nextSibling;
  29385. scopeNode = this._container;
  29386. lineNumber = lastUndamagedLineRow.lineNumber + 1;
  29387. }
  29388. }
  29389.  
  29390.  
  29391. if (container === node && offset === 0)
  29392. return { line: lineNumber, column: 0 };
  29393.  
  29394.  
  29395. for (; node && node !== container; node = node.traverseNextNode(scopeNode)) {
  29396. if (node.nodeName.toLowerCase() === "br") {
  29397. lineNumber++;
  29398. column = 0;
  29399. } else if (node.nodeType === Node.TEXT_NODE) {
  29400. var text = node.textContent;
  29401. for (var i = 0; i < text.length; ++i) {
  29402. if (text.charAt(i) === "\n") {
  29403. lineNumber++;
  29404. column = 0;
  29405. } else
  29406. column++;
  29407. }
  29408. }
  29409. }
  29410.  
  29411.  
  29412. if (node === container && offset) {
  29413. var text = node.textContent;
  29414.  
  29415. var textOffset = (node._chunk && offset === 1) ? text.length : offset;
  29416. for (var i = 0; i < textOffset; ++i) {
  29417. if (text.charAt(i) === "\n") {
  29418. lineNumber++;
  29419. column = 0;
  29420. } else
  29421. column++;
  29422. }
  29423. }
  29424. return { line: lineNumber, column: column };
  29425. },
  29426.  
  29427.  
  29428. _positionToSelection: function(line, column)
  29429. {
  29430. var chunk = this.chunkForLine(line);
  29431.  
  29432. var lineRow = chunk.linesCount === 1 ? chunk.element : chunk.expandedLineRow(line);
  29433. if (lineRow)
  29434. var rangeBoundary = lineRow.rangeBoundaryForOffset(column);
  29435. else {
  29436. var offset = column;
  29437. for (var i = chunk.startLine; i < line && i < this._textModel.linesCount; ++i)
  29438. offset += this._textModel.lineLength(i) + 1; 
  29439. lineRow = chunk.element;
  29440. if (lineRow.firstChild)
  29441. var rangeBoundary = { container: lineRow.firstChild, offset: offset };
  29442. else
  29443. var rangeBoundary = { container: lineRow, offset: 0 };
  29444. }
  29445. return rangeBoundary;
  29446. },
  29447.  
  29448.  
  29449. _enclosingLineRowOrSelf: function(element)
  29450. {
  29451. var lineRow = element.enclosingNodeOrSelfWithClass("webkit-line-content");
  29452. if (lineRow)
  29453. return lineRow;
  29454.  
  29455. for (lineRow = element; lineRow; lineRow = lineRow.parentElement) {
  29456. if (lineRow.parentElement === this._container)
  29457. return lineRow;
  29458. }
  29459. return null;
  29460. },
  29461.  
  29462.  
  29463. _insertSpanBefore: function(element, oldChild, content, className)
  29464. {
  29465. if (className === "html-resource-link" || className === "html-external-link") {
  29466. element.insertBefore(this._createLink(content, className === "html-external-link"), oldChild);
  29467. return;
  29468. }
  29469.  
  29470. var span = this._cachedSpans.pop() || document.createElement("span");
  29471. span.className = "webkit-" + className;
  29472. if (WebInspector.FALSE) 
  29473. span.addStyleClass("debug-fadeout");
  29474. span.textContent = content;
  29475. element.insertBefore(span, oldChild);
  29476. if (!("spans" in element))
  29477. element.spans = [];
  29478. element.spans.push(span);
  29479. },
  29480.  
  29481.  
  29482. _insertTextNodeBefore: function(element, oldChild, text)
  29483. {
  29484. var textNode = this._cachedTextNodes.pop();
  29485. if (textNode)
  29486. textNode.nodeValue = text;
  29487. else
  29488. textNode = document.createTextNode(text);
  29489. element.insertBefore(textNode, oldChild);
  29490. if (!("textNodes" in element))
  29491. element.textNodes = [];
  29492. element.textNodes.push(textNode);
  29493. },
  29494.  
  29495.  
  29496. _createLink: function(content, isExternal)
  29497. {
  29498. var quote = content.charAt(0);
  29499. if (content.length > 1 && (quote === "\"" ||   quote === "'"))
  29500. content = content.substring(1, content.length - 1);
  29501. else
  29502. quote = null;
  29503.  
  29504. var span = document.createElement("span");
  29505. span.className = "webkit-html-attribute-value";
  29506. if (quote)
  29507. span.appendChild(document.createTextNode(quote));
  29508. span.appendChild(this._delegate.createLink(content, isExternal));
  29509. if (quote)
  29510. span.appendChild(document.createTextNode(quote));
  29511. return span;
  29512. },
  29513.  
  29514.  
  29515. _handleMutations: function(mutations)
  29516. {
  29517. if (this._readOnly) {
  29518. delete this._keyDownCode;
  29519. return;
  29520. }
  29521.  
  29522.  
  29523. var filteredMutations = mutations.slice();
  29524. var addedBRs = new Map();
  29525. for (var i = 0; i < mutations.length; ++i) {
  29526. var mutation = mutations[i];
  29527. if (mutation.type !== "childList")
  29528. continue;
  29529. if (mutation.addedNodes.length === 1 && mutation.addedNodes[0].nodeName === "BR")
  29530. addedBRs.put(mutation.addedNodes[0], mutation);
  29531. else if (mutation.removedNodes.length === 1 && mutation.removedNodes[0].nodeName === "BR") {
  29532. var noopMutation = addedBRs.get(mutation.removedNodes[0]);
  29533. if (noopMutation) {
  29534. filteredMutations.remove(mutation);
  29535. filteredMutations.remove(noopMutation);
  29536. }
  29537. }
  29538. }
  29539.  
  29540. var dirtyLines;
  29541. for (var i = 0; i < filteredMutations.length; ++i) {
  29542. var mutation = filteredMutations[i];
  29543. var changedNodes = [];
  29544. if (mutation.type === "childList" && mutation.addedNodes.length)
  29545. changedNodes = Array.prototype.slice.call(mutation.addedNodes);
  29546. else if (mutation.type === "childList" && mutation.removedNodes.length)
  29547. changedNodes = Array.prototype.slice.call(mutation.removedNodes);
  29548. changedNodes.push(mutation.target);
  29549.  
  29550. for (var j = 0; j < changedNodes.length; ++j) {
  29551. var lines = this._collectDirtyLines(mutation, changedNodes[j]);
  29552. if (!lines)
  29553. continue;
  29554. if (!dirtyLines) {
  29555. dirtyLines = lines;
  29556. continue;
  29557. }
  29558. dirtyLines.start = Math.min(dirtyLines.start, lines.start);
  29559. dirtyLines.end = Math.max(dirtyLines.end, lines.end);
  29560. }
  29561. }
  29562. if (dirtyLines) {
  29563. delete this._rangeToMark;
  29564. this._applyDomUpdates(dirtyLines);
  29565. }
  29566.  
  29567. this._assertDOMMatchesTextModel();
  29568.  
  29569. delete this._keyDownCode;
  29570. },
  29571.  
  29572.  
  29573. _collectDirtyLines: function(mutation, target)
  29574. {
  29575. var lineRow = this._enclosingLineRowOrSelf(target);
  29576. if (!lineRow)
  29577. return null;
  29578.  
  29579. if (lineRow.decorationsElement && lineRow.decorationsElement.isSelfOrAncestor(target)) {
  29580. if (this._syncDecorationsForLineListener)
  29581. this._syncDecorationsForLineListener(lineRow.lineNumber);
  29582. return null;
  29583. }
  29584.  
  29585. if (typeof lineRow.lineNumber !== "number")
  29586. return null;
  29587.  
  29588. var startLine = lineRow.lineNumber;
  29589. var endLine = lineRow._chunk ? lineRow._chunk.endLine - 1 : lineRow.lineNumber;
  29590. return { start: startLine, end: endLine };
  29591. },
  29592.  
  29593.  
  29594. _applyDomUpdates: function(dirtyLines)
  29595. {
  29596. var lastUndamagedLineNumber = dirtyLines.start - 1; 
  29597. var firstUndamagedLineNumber = dirtyLines.end + 1; 
  29598.  
  29599. var lastUndamagedLineChunk = lastUndamagedLineNumber >= 0 ? this._textChunks[this._chunkNumberForLine(lastUndamagedLineNumber)] : null;
  29600. var firstUndamagedLineChunk = firstUndamagedLineNumber  < this._textModel.linesCount ? this._textChunks[this._chunkNumberForLine(firstUndamagedLineNumber)] : null;
  29601.  
  29602. var collectLinesFromNode = lastUndamagedLineChunk ? lastUndamagedLineChunk.lineRowContainingLine(lastUndamagedLineNumber) : null;
  29603. var collectLinesToNode = firstUndamagedLineChunk ? firstUndamagedLineChunk.lineRowContainingLine(firstUndamagedLineNumber) : null;
  29604. var lines = this._collectLinesFromDOM(collectLinesFromNode, collectLinesToNode);
  29605.  
  29606. var startLine = dirtyLines.start;
  29607. var endLine = dirtyLines.end;
  29608.  
  29609. var editInfo = this._guessEditRangeBasedOnSelection(startLine, endLine, lines);
  29610. if (!editInfo) {
  29611. if (WebInspector.debugDefaultTextEditor)
  29612. console.warn("Falling back to expensive edit");
  29613. var range = new WebInspector.TextRange(startLine, 0, endLine, this._textModel.lineLength(endLine));
  29614. if (!lines.length) {
  29615.  
  29616. editInfo = new WebInspector.DefaultTextEditor.EditInfo(this._textModel.growRangeRight(range), "");
  29617. } else
  29618. editInfo = new WebInspector.DefaultTextEditor.EditInfo(range, lines.join("\n"));
  29619. }
  29620.  
  29621. var selection = this._getSelection(collectLinesFromNode);
  29622.  
  29623.  
  29624. if (editInfo.text === "}" && editInfo.range.isEmpty() && selection.isEmpty() && !this._textModel.line(editInfo.range.endLine).trim()) {
  29625. var offset = this._closingBlockOffset(editInfo.range, selection);
  29626. if (offset >= 0) {
  29627. editInfo.range.startColumn = offset;
  29628. selection.startColumn = offset + 1;
  29629. selection.endColumn = offset + 1;
  29630. }
  29631. }
  29632.  
  29633. this._textModel.editRange(editInfo.range, editInfo.text);
  29634. this._paintScheduledLines(true);
  29635. this._restoreSelection(selection);
  29636. },
  29637.  
  29638.  
  29639. _guessEditRangeBasedOnSelection: function(startLine, endLine, lines)
  29640. {
  29641.  
  29642. var textInputData = this._textInputData;
  29643. delete this._textInputData;
  29644. var isBackspace = this._keyDownCode === WebInspector.KeyboardShortcut.Keys.Backspace.code;
  29645. var isDelete = this._keyDownCode === WebInspector.KeyboardShortcut.Keys.Delete.code;
  29646.  
  29647. if (!textInputData && (isDelete || isBackspace))
  29648. textInputData = "";
  29649.  
  29650.  
  29651. if (typeof textInputData === "undefined" || !this._lastSelection)
  29652. return null;
  29653.  
  29654.  
  29655. textInputData = textInputData || "";
  29656. var range = this._lastSelection.normalize();
  29657. if (isBackspace && range.isEmpty())
  29658. range = this._textModel.growRangeLeft(range);
  29659. else if (isDelete && range.isEmpty())
  29660. range = this._textModel.growRangeRight(range);
  29661.  
  29662.  
  29663. if (startLine > range.endLine || endLine < range.startLine)
  29664. return null;
  29665.  
  29666. var replacementLineCount = textInputData.split("\n").length - 1;
  29667. var lineCountDelta = replacementLineCount - range.linesCount;
  29668. if (startLine + lines.length - endLine - 1 !== lineCountDelta)
  29669. return null;
  29670.  
  29671.  
  29672. var cloneFromLine = Math.min(range.startLine, startLine);
  29673. var postLastLine = startLine + lines.length + lineCountDelta;
  29674. var cloneToLine = Math.min(Math.max(postLastLine, range.endLine) + 1, this._textModel.linesCount);
  29675. var domModel = this._textModel.slice(cloneFromLine, cloneToLine);
  29676. domModel.editRange(range.shift(-cloneFromLine), textInputData);
  29677.  
  29678.  
  29679. for (var i = 0;  i < lines.length; ++i) {
  29680. if (domModel.line(i + startLine - cloneFromLine) !== lines[i])
  29681. return null;
  29682. }
  29683. return new WebInspector.DefaultTextEditor.EditInfo(range, textInputData);
  29684. },
  29685.  
  29686. _assertDOMMatchesTextModel: function()
  29687. {
  29688. if (!WebInspector.debugDefaultTextEditor)
  29689. return;
  29690.  
  29691. console.assert(this.element.innerText === this._textModel.text() + "\n", "DOM does not match model.");
  29692. for (var lineRow = this._container.firstChild; lineRow; lineRow = lineRow.nextSibling) {
  29693. var lineNumber = lineRow.lineNumber;
  29694. if (typeof lineNumber !== "number") {
  29695. console.warn("No line number on line row");
  29696. continue;
  29697. }
  29698. if (lineRow._chunk) {
  29699. var chunk = lineRow._chunk;
  29700. console.assert(lineNumber === chunk.startLine);
  29701. var chunkText = this._textModel.copyRange(new WebInspector.TextRange(chunk.startLine, 0, chunk.endLine - 1, this._textModel.lineLength(chunk.endLine - 1)));
  29702. if (chunkText !== lineRow.textContent)
  29703. console.warn("Chunk is not matching: %d %O", lineNumber, lineRow);
  29704. } else if (this._textModel.line(lineNumber) !== lineRow.textContent)
  29705. console.warn("Line is not matching: %d %O", lineNumber, lineRow);
  29706. }
  29707. },
  29708.  
  29709.  
  29710. _closingBlockOffset: function(oldRange, selection)
  29711. {
  29712. var nestingLevel = 1;
  29713. for (var i = oldRange.endLine; i >= 0; --i) {
  29714. var attribute = this._textModel.getAttribute(i, "highlight");
  29715. if (!attribute)
  29716. continue;
  29717. var columnNumbers = Object.keys(attribute).reverse();
  29718. for (var j = 0; j < columnNumbers.length; ++j) {
  29719. var column = columnNumbers[j];
  29720. if (attribute[column].tokenType === "block-start") {
  29721. if (!(--nestingLevel)) {
  29722. var lineContent = this._textModel.line(i);
  29723. return lineContent.length - lineContent.trimLeft().length;
  29724. }
  29725. }
  29726. if (attribute[column].tokenType === "block-end")
  29727. ++nestingLevel;
  29728. }
  29729. }
  29730. return -1;
  29731. },
  29732.  
  29733.  
  29734. textChanged: function(oldRange, newRange)
  29735. {
  29736. this.beginDomUpdates();
  29737. this._removeDecorationsInRange(oldRange);
  29738. this._updateChunksForRanges(oldRange, newRange);
  29739. this._updateHighlightsForRange(newRange);
  29740. this.endDomUpdates();
  29741. },
  29742.  
  29743.  
  29744. _removeDecorationsInRange: function(range)
  29745. {
  29746. for (var i = this._chunkNumberForLine(range.startLine); i < this._textChunks.length; ++i) {
  29747. var chunk = this._textChunks[i];
  29748. if (chunk.startLine > range.endLine)
  29749. break;
  29750. chunk.removeAllDecorations();
  29751. }
  29752. },
  29753.  
  29754.  
  29755. _updateChunksForRanges: function(oldRange, newRange)
  29756. {
  29757. var firstDamagedChunkNumber = this._chunkNumberForLine(oldRange.startLine);
  29758. var lastDamagedChunkNumber = firstDamagedChunkNumber;
  29759. while (lastDamagedChunkNumber + 1 < this._textChunks.length) {
  29760. if (this._textChunks[lastDamagedChunkNumber + 1].startLine > oldRange.endLine)
  29761. break;
  29762. ++lastDamagedChunkNumber;
  29763. }
  29764.  
  29765. var firstDamagedChunk = this._textChunks[firstDamagedChunkNumber];
  29766. var lastDamagedChunk = this._textChunks[lastDamagedChunkNumber];
  29767.  
  29768. var linesDiff = newRange.linesCount - oldRange.linesCount;
  29769.  
  29770.  
  29771. if (linesDiff) {
  29772. for (var chunkNumber = lastDamagedChunkNumber + 1; chunkNumber < this._textChunks.length; ++chunkNumber)
  29773. this._textChunks[chunkNumber].startLine += linesDiff;
  29774. }
  29775.  
  29776.  
  29777. var lastUndamagedChunk = firstDamagedChunkNumber > 0 ? this._textChunks[firstDamagedChunkNumber - 1] : null;
  29778. var firstUndamagedChunk = lastDamagedChunkNumber + 1 < this._textChunks.length ? this._textChunks[lastDamagedChunkNumber + 1] : null;
  29779.  
  29780. var removeDOMFromNode = lastUndamagedChunk ? lastUndamagedChunk.lastElement().nextSibling : this._container.firstChild;
  29781. var removeDOMToNode = firstUndamagedChunk ? firstUndamagedChunk.firstElement() : null;
  29782.  
  29783.  
  29784. if (!linesDiff && firstDamagedChunk === lastDamagedChunk && firstDamagedChunk._expandedLineRows) {
  29785. var lastUndamagedLineRow = lastDamagedChunk.expandedLineRow(oldRange.startLine - 1);
  29786. var firstUndamagedLineRow = firstDamagedChunk.expandedLineRow(oldRange.endLine + 1);
  29787. var localRemoveDOMFromNode = lastUndamagedLineRow ? lastUndamagedLineRow.nextSibling : removeDOMFromNode;
  29788. var localRemoveDOMToNode = firstUndamagedLineRow || removeDOMToNode;
  29789. removeSubsequentNodes(localRemoveDOMFromNode, localRemoveDOMToNode);
  29790. for (var i = newRange.startLine; i < newRange.endLine + 1; ++i) {
  29791. var row = firstDamagedChunk._createRow(i);
  29792. firstDamagedChunk._expandedLineRows[i - firstDamagedChunk.startLine] = row;
  29793. this._container.insertBefore(row, localRemoveDOMToNode);
  29794. }
  29795. firstDamagedChunk.updateCollapsedLineRow();
  29796. this._assertDOMMatchesTextModel();
  29797. return;
  29798. }
  29799.  
  29800. removeSubsequentNodes(removeDOMFromNode, removeDOMToNode);
  29801. this._textChunks.splice(firstDamagedChunkNumber, lastDamagedChunkNumber - firstDamagedChunkNumber + 1);
  29802.  
  29803.  
  29804. var startLine = firstDamagedChunk.startLine;
  29805. var endLine = lastDamagedChunk.endLine + linesDiff;
  29806. var lineSpan = endLine - startLine;
  29807.  
  29808.  
  29809. var insertionIndex = firstDamagedChunkNumber;
  29810. var chunkSize = Math.ceil(lineSpan / Math.ceil(lineSpan / this._defaultChunkSize));
  29811.  
  29812. for (var i = startLine; i < endLine; i += chunkSize) {
  29813. var chunk = this._createNewChunk(i, Math.min(endLine, i + chunkSize));
  29814. this._textChunks.splice(insertionIndex++, 0, chunk);
  29815. this._container.insertBefore(chunk.element, removeDOMToNode);
  29816. }
  29817.  
  29818. this._assertDOMMatchesTextModel();
  29819. },
  29820.  
  29821.  
  29822. _updateHighlightsForRange: function(range)
  29823. {
  29824. var visibleFrom = this._scrollTop();
  29825. var visibleTo = visibleFrom + this._clientHeight();
  29826.  
  29827. var result = this._findVisibleChunks(visibleFrom, visibleTo);
  29828. var chunk = this._textChunks[result.end - 1];
  29829. var lastVisibleLine = chunk.startLine + chunk.linesCount;
  29830.  
  29831. lastVisibleLine = Math.max(lastVisibleLine, range.endLine + 1);
  29832. lastVisibleLine = Math.min(lastVisibleLine, this._textModel.linesCount);
  29833.  
  29834. var updated = this._highlighter.updateHighlight(range.startLine, lastVisibleLine);
  29835. if (!updated) {
  29836.  
  29837. for (var i = this._chunkNumberForLine(range.startLine); i < this._textChunks.length; ++i)
  29838. this._textChunks[i].expanded = false;
  29839. }
  29840.  
  29841. this._repaintAll();
  29842. },
  29843.  
  29844.  
  29845. _collectLinesFromDOM: function(from, to)
  29846. {
  29847. var textContents = [];
  29848. var hasContent = false;
  29849. for (var node = from ? from.nextSibling : this._container; node && node !== to; node = node.traverseNextNode(this._container)) {
  29850. if (node._isDecorationsElement) {
  29851.  
  29852. node = node.nextSibling;
  29853. if (!node || node === to)
  29854. break;
  29855. }
  29856. hasContent = true;
  29857. if (node.nodeName.toLowerCase() === "br")
  29858. textContents.push("\n");
  29859. else if (node.nodeType === Node.TEXT_NODE)
  29860. textContents.push(node.textContent);
  29861. }
  29862. if (!hasContent)
  29863. return [];
  29864.  
  29865. var textContent = textContents.join("");
  29866.  
  29867. textContent = textContent.replace(/\n$/, "");
  29868.  
  29869. return textContent.split("\n");
  29870. },
  29871.  
  29872. _handleSelectionChange: function(event)
  29873. {
  29874. var textRange = this._getSelection();
  29875. if (textRange)
  29876. this._lastSelection = textRange;
  29877. this._delegate.selectionChanged(textRange);
  29878. },
  29879.  
  29880. __proto__: WebInspector.TextEditorChunkedPanel.prototype
  29881. }
  29882.  
  29883.  
  29884. WebInspector.TextEditorMainChunk = function(chunkedPanel, startLine, endLine)
  29885. {
  29886. this._chunkedPanel = chunkedPanel;
  29887. this._textModel = chunkedPanel._textModel;
  29888.  
  29889. this.element = document.createElement("div");
  29890. this.element.lineNumber = startLine;
  29891. this.element.className = "webkit-line-content";
  29892. this.element._chunk = this;
  29893.  
  29894. this._startLine = startLine;
  29895. endLine = Math.min(this._textModel.linesCount, endLine);
  29896. this.linesCount = endLine - startLine;
  29897.  
  29898. this._expanded = false;
  29899.  
  29900. this.updateCollapsedLineRow();
  29901. }
  29902.  
  29903. WebInspector.TextEditorMainChunk.prototype = {
  29904. addDecoration: function(decoration)
  29905. {
  29906. this._chunkedPanel.beginDomUpdates();
  29907. if (typeof decoration === "string")
  29908. this.element.addStyleClass(decoration);
  29909. else {
  29910. if (!this.element.decorationsElement) {
  29911. this.element.decorationsElement = document.createElement("div");
  29912. this.element.decorationsElement.className = "webkit-line-decorations";
  29913. this.element.decorationsElement._isDecorationsElement = true;
  29914. this.element.appendChild(this.element.decorationsElement);
  29915. }
  29916. this.element.decorationsElement.appendChild(decoration);
  29917. }
  29918. this._chunkedPanel.endDomUpdates();
  29919. },
  29920.  
  29921.  
  29922. removeDecoration: function(decoration)
  29923. {
  29924. this._chunkedPanel.beginDomUpdates();
  29925. if (typeof decoration === "string")
  29926. this.element.removeStyleClass(decoration);
  29927. else if (this.element.decorationsElement)
  29928. this.element.decorationsElement.removeChild(decoration);
  29929. this._chunkedPanel.endDomUpdates();
  29930. },
  29931.  
  29932. removeAllDecorations: function()
  29933. {
  29934. this._chunkedPanel.beginDomUpdates();
  29935. this.element.className = "webkit-line-content";
  29936. if (this.element.decorationsElement) {
  29937. this.element.removeChild(this.element.decorationsElement);
  29938. delete this.element.decorationsElement;
  29939. }
  29940. this._chunkedPanel.endDomUpdates();
  29941. },
  29942.  
  29943.  
  29944. isDecorated: function()
  29945. {
  29946. return this.element.className !== "webkit-line-content" || !!(this.element.decorationsElement && this.element.decorationsElement.firstChild);
  29947. },
  29948.  
  29949.  
  29950. get startLine()
  29951. {
  29952. return this._startLine;
  29953. },
  29954.  
  29955.  
  29956. get endLine()
  29957. {
  29958. return this._startLine + this.linesCount;
  29959. },
  29960.  
  29961. set startLine(startLine)
  29962. {
  29963. this._startLine = startLine;
  29964. this.element.lineNumber = startLine;
  29965. if (this._expandedLineRows) {
  29966. for (var i = 0; i < this._expandedLineRows.length; ++i)
  29967. this._expandedLineRows[i].lineNumber = startLine + i;
  29968. }
  29969. },
  29970.  
  29971.  
  29972. get expanded()
  29973. {
  29974. return this._expanded;
  29975. },
  29976.  
  29977. set expanded(expanded)
  29978. {
  29979. if (this._expanded === expanded)
  29980. return;
  29981.  
  29982. this._expanded = expanded;
  29983.  
  29984. if (this.linesCount === 1) {
  29985. if (expanded)
  29986. this._chunkedPanel._paintLine(this.element);
  29987. return;
  29988. }
  29989.  
  29990. this._chunkedPanel.beginDomUpdates();
  29991.  
  29992. if (expanded) {
  29993. this._expandedLineRows = [];
  29994. var parentElement = this.element.parentElement;
  29995. for (var i = this.startLine; i < this.startLine + this.linesCount; ++i) {
  29996. var lineRow = this._createRow(i);
  29997. parentElement.insertBefore(lineRow, this.element);
  29998. this._expandedLineRows.push(lineRow);
  29999. }
  30000. parentElement.removeChild(this.element);
  30001. this._chunkedPanel._paintLines(this.startLine, this.startLine + this.linesCount);
  30002. } else {
  30003. var elementInserted = false;
  30004. for (var i = 0; i < this._expandedLineRows.length; ++i) {
  30005. var lineRow = this._expandedLineRows[i];
  30006. var parentElement = lineRow.parentElement;
  30007. if (parentElement) {
  30008. if (!elementInserted) {
  30009. elementInserted = true;
  30010. parentElement.insertBefore(this.element, lineRow);
  30011. }
  30012. parentElement.removeChild(lineRow);
  30013. }
  30014. this._chunkedPanel._releaseLinesHighlight(lineRow);
  30015. }
  30016. delete this._expandedLineRows;
  30017. }
  30018.  
  30019. this._chunkedPanel.endDomUpdates();
  30020. },
  30021.  
  30022.  
  30023. get height()
  30024. {
  30025. if (!this._expandedLineRows)
  30026. return this._chunkedPanel._totalHeight(this.element);
  30027. return this._chunkedPanel._totalHeight(this._expandedLineRows[0], this._expandedLineRows[this._expandedLineRows.length - 1]);
  30028. },
  30029.  
  30030.  
  30031. get offsetTop()
  30032. {
  30033. return (this._expandedLineRows && this._expandedLineRows.length) ? this._expandedLineRows[0].offsetTop : this.element.offsetTop;
  30034. },
  30035.  
  30036.  
  30037. _createRow: function(lineNumber)
  30038. {
  30039. var lineRow = this._chunkedPanel._cachedRows.pop() || document.createElement("div");
  30040. lineRow.lineNumber = lineNumber;
  30041. lineRow.className = "webkit-line-content";
  30042. lineRow.textContent = this._textModel.line(lineNumber);
  30043. if (!lineRow.textContent)
  30044. lineRow.appendChild(document.createElement("br"));
  30045. return lineRow;
  30046. },
  30047.  
  30048.  
  30049. lineRowContainingLine: function(lineNumber)
  30050. {
  30051. if (!this._expanded)
  30052. return this.element;
  30053. return this.expandedLineRow(lineNumber);
  30054. },
  30055.  
  30056.  
  30057. expandedLineRow: function(lineNumber)
  30058. {
  30059. if (!this._expanded || lineNumber < this.startLine || lineNumber >= this.startLine + this.linesCount)
  30060. return null;
  30061. if (!this._expandedLineRows)
  30062. return this.element;
  30063. return this._expandedLineRows[lineNumber - this.startLine];
  30064. },
  30065.  
  30066. updateCollapsedLineRow: function()
  30067. {
  30068. if (this.linesCount === 1 && this._expanded)
  30069. return;
  30070.  
  30071. var lines = [];
  30072. for (var i = this.startLine; i < this.startLine + this.linesCount; ++i)
  30073. lines.push(this._textModel.line(i));
  30074.  
  30075. if (WebInspector.FALSE)
  30076. console.log("Rebuilding chunk with " + lines.length + " lines");
  30077.  
  30078. this.element.removeChildren();
  30079. this.element.textContent = lines.join("\n");
  30080.  
  30081. if (!lines[lines.length - 1])
  30082. this.element.appendChild(document.createElement("br"));
  30083. },
  30084.  
  30085. firstElement: function()
  30086. {
  30087. return this._expandedLineRows ? this._expandedLineRows[0] : this.element;
  30088. },
  30089.  
  30090. lastElement: function()
  30091. {
  30092. return this._expandedLineRows ? this._expandedLineRows[this._expandedLineRows.length - 1] : this.element;
  30093. }
  30094. }
  30095.  
  30096. WebInspector.debugDefaultTextEditor = false;
  30097.  
  30098.  
  30099.  
  30100.  
  30101.  
  30102.  
  30103. WebInspector.SourceFrame = function(contentProvider)
  30104. {
  30105. WebInspector.View.call(this);
  30106. this.element.addStyleClass("script-view");
  30107.  
  30108. this._url = contentProvider.contentURL();
  30109. this._contentProvider = contentProvider;
  30110.  
  30111. var textEditorDelegate = new WebInspector.TextEditorDelegateForSourceFrame(this);
  30112.  
  30113. if (WebInspector.experimentsSettings.codemirror.isEnabled()) {
  30114. importScript("CodeMirrorTextEditor.js");
  30115. this._textEditor = new WebInspector.CodeMirrorTextEditor(this._url, textEditorDelegate);
  30116. } else
  30117. this._textEditor = new WebInspector.DefaultTextEditor(this._url, textEditorDelegate);
  30118.  
  30119. this._currentSearchResultIndex = -1;
  30120. this._searchResults = [];
  30121.  
  30122. this._messages = [];
  30123. this._rowMessages = {};
  30124. this._messageBubbles = {};
  30125.  
  30126. this._textEditor.setReadOnly(!this.canEditSource());
  30127.  
  30128. this._shortcuts = {};
  30129. this._shortcuts[WebInspector.KeyboardShortcut.makeKey("s", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)] = this._commitEditing.bind(this);
  30130. this.element.addEventListener("keydown", this._handleKeyDown.bind(this), false);
  30131. }
  30132.  
  30133.  
  30134. WebInspector.SourceFrame.createSearchRegex = function(query, modifiers)
  30135. {
  30136. var regex;
  30137. modifiers = modifiers || "";
  30138.  
  30139.  
  30140. try {
  30141. if (/^\/.*\/$/.test(query))
  30142. regex = new RegExp(query.substring(1, query.length - 1), modifiers);
  30143. } catch (e) {
  30144.  
  30145. }
  30146.  
  30147.  
  30148. if (!regex)
  30149. regex = createPlainTextSearchRegex(query, "i" + modifiers);
  30150.  
  30151. return regex;
  30152. }
  30153.  
  30154. WebInspector.SourceFrame.Events = {
  30155. ScrollChanged: "ScrollChanged",
  30156. SelectionChanged: "SelectionChanged"
  30157. }
  30158.  
  30159. WebInspector.SourceFrame.prototype = {
  30160. wasShown: function()
  30161. {
  30162. this._ensureContentLoaded();
  30163. this._textEditor.show(this.element);
  30164. this._wasShownOrLoaded();
  30165. },
  30166.  
  30167. willHide: function()
  30168. {
  30169. WebInspector.View.prototype.willHide.call(this);
  30170.  
  30171. this._clearLineHighlight();
  30172. this._clearLineToReveal();
  30173. },
  30174.  
  30175.  
  30176. statusBarItems: function()
  30177. {
  30178. return [];
  30179. },
  30180.  
  30181. defaultFocusedElement: function()
  30182. {
  30183. return this._textEditor.defaultFocusedElement();
  30184. },
  30185.  
  30186. get loaded()
  30187. {
  30188. return this._loaded;
  30189. },
  30190.  
  30191. hasContent: function()
  30192. {
  30193. return true;
  30194. },
  30195.  
  30196. get textEditor()
  30197. {
  30198. return this._textEditor;
  30199. },
  30200.  
  30201. _ensureContentLoaded: function()
  30202. {
  30203. if (!this._contentRequested) {
  30204. this._contentRequested = true;
  30205. this._contentProvider.requestContent(this.setContent.bind(this));
  30206. }
  30207. },
  30208.  
  30209. addMessage: function(msg)
  30210. {
  30211. this._messages.push(msg);
  30212. if (this.loaded)
  30213. this.addMessageToSource(msg.line - 1, msg);
  30214. },
  30215.  
  30216. clearMessages: function()
  30217. {
  30218. for (var line in this._messageBubbles) {
  30219. var bubble = this._messageBubbles[line];
  30220. bubble.parentNode.removeChild(bubble);
  30221. }
  30222.  
  30223. this._messages = [];
  30224. this._rowMessages = {};
  30225. this._messageBubbles = {};
  30226.  
  30227. this._textEditor.doResize();
  30228. },
  30229.  
  30230.  
  30231. canHighlightLine: function(line)
  30232. {
  30233. return true;
  30234. },
  30235.  
  30236.  
  30237. highlightLine: function(line)
  30238. {
  30239. this._clearLineToReveal();
  30240. this._clearLineToScrollTo();
  30241. this._lineToHighlight = line;
  30242. this._innerHighlightLineIfNeeded();
  30243. this._textEditor.setSelection(WebInspector.TextRange.createFromLocation(line, 0));
  30244. },
  30245.  
  30246. _innerHighlightLineIfNeeded: function()
  30247. {
  30248. if (typeof this._lineToHighlight === "number") {
  30249. if (this.loaded && this._textEditor.isShowing()) {
  30250. this._textEditor.highlightLine(this._lineToHighlight);
  30251. delete this._lineToHighlight
  30252. }
  30253. }
  30254. },
  30255.  
  30256. _clearLineHighlight: function()
  30257. {
  30258. this._textEditor.clearLineHighlight();
  30259. delete this._lineToHighlight;
  30260. },
  30261.  
  30262.  
  30263. revealLine: function(line)
  30264. {
  30265. this._clearLineHighlight();
  30266. this._clearLineToScrollTo();
  30267. this._lineToReveal = line;
  30268. this._innerRevealLineIfNeeded();
  30269. },
  30270.  
  30271. _innerRevealLineIfNeeded: function()
  30272. {
  30273. if (typeof this._lineToReveal === "number") {
  30274. if (this.loaded && this._textEditor.isShowing()) {
  30275. this._textEditor.revealLine(this._lineToReveal);
  30276. delete this._lineToReveal
  30277. }
  30278. }
  30279. },
  30280.  
  30281. _clearLineToReveal: function()
  30282. {
  30283. delete this._lineToReveal;
  30284. },
  30285.  
  30286.  
  30287. scrollToLine: function(line)
  30288. {
  30289. this._clearLineHighlight();
  30290. this._clearLineToReveal();
  30291. this._lineToScrollTo = line;
  30292. this._innerScrollToLineIfNeeded();
  30293. },
  30294.  
  30295. _innerScrollToLineIfNeeded: function()
  30296. {
  30297. if (typeof this._lineToScrollTo === "number") {
  30298. if (this.loaded && this._textEditor.isShowing()) {
  30299. this._textEditor.scrollToLine(this._lineToScrollTo);
  30300. delete this._lineToScrollTo
  30301. }
  30302. }
  30303. },
  30304.  
  30305. _clearLineToScrollTo: function()
  30306. {
  30307. delete this._lineToScrollTo;
  30308. },
  30309.  
  30310.  
  30311. setSelection: function(textRange)
  30312. {
  30313. this._selectionToSet = textRange;
  30314. this._innerSetSelectionIfNeeded();
  30315. },
  30316.  
  30317. _innerSetSelectionIfNeeded: function()
  30318. {
  30319. if (this._selectionToSet && this.loaded && this._textEditor.isShowing()) {
  30320. this._textEditor.setSelection(this._selectionToSet);
  30321. delete this._selectionToSet;
  30322. }
  30323. },
  30324.  
  30325. _wasShownOrLoaded: function()
  30326. {
  30327. this._innerHighlightLineIfNeeded();
  30328. this._innerRevealLineIfNeeded();
  30329. this._innerScrollToLineIfNeeded();
  30330. this._innerSetSelectionIfNeeded();
  30331. },
  30332.  
  30333. onTextChanged: function(oldRange, newRange)
  30334. {
  30335. if (!this._isReplacing)
  30336. WebInspector.searchController.cancelSearch();
  30337. this.clearMessages();
  30338. },
  30339.  
  30340.  
  30341. setContent: function(content, contentEncoded, mimeType)
  30342. {
  30343. this._textEditor.mimeType = mimeType;
  30344.  
  30345. this._loaded = true;
  30346. this._textEditor.setText(content || "");
  30347.  
  30348. this._textEditor.beginUpdates();
  30349.  
  30350. this._setTextEditorDecorations();
  30351.  
  30352. this._wasShownOrLoaded();
  30353.  
  30354. if (this._delayedFindSearchMatches) {
  30355. this._delayedFindSearchMatches();
  30356. delete this._delayedFindSearchMatches;
  30357. }
  30358.  
  30359. this.onTextEditorContentLoaded();
  30360.  
  30361. this._textEditor.endUpdates();
  30362. },
  30363.  
  30364. onTextEditorContentLoaded: function() {},
  30365.  
  30366. _setTextEditorDecorations: function()
  30367. {
  30368. this._rowMessages = {};
  30369. this._messageBubbles = {};
  30370.  
  30371. this._textEditor.beginUpdates();
  30372.  
  30373. this._addExistingMessagesToSource();
  30374.  
  30375. this._textEditor.doResize();
  30376.  
  30377. this._textEditor.endUpdates();
  30378. },
  30379.  
  30380.  
  30381. performSearch: function(query, callback)
  30382. {
  30383.  
  30384. this.searchCanceled();
  30385.  
  30386. function doFindSearchMatches(query)
  30387. {
  30388. this._currentSearchResultIndex = -1;
  30389. this._searchResults = [];
  30390.  
  30391. var regex = WebInspector.SourceFrame.createSearchRegex(query);
  30392. this._searchResults = this._collectRegexMatches(regex);
  30393. var shiftToIndex = 0;
  30394. var selection = this._textEditor.lastSelection();
  30395. for (var i = 0; selection && i < this._searchResults.length; ++i) {
  30396. if (this._searchResults[i].compareTo(selection) >= 0) {
  30397. shiftToIndex = i;
  30398. break;
  30399. }
  30400. }
  30401.  
  30402. if (shiftToIndex)
  30403. this._searchResults = this._searchResults.rotate(shiftToIndex);
  30404.  
  30405. callback(this, this._searchResults.length);
  30406. }
  30407.  
  30408. if (this.loaded)
  30409. doFindSearchMatches.call(this, query);
  30410. else
  30411. this._delayedFindSearchMatches = doFindSearchMatches.bind(this, query);
  30412.  
  30413. this._ensureContentLoaded();
  30414. },
  30415.  
  30416. searchCanceled: function()
  30417. {
  30418. delete this._delayedFindSearchMatches;
  30419. if (!this.loaded)
  30420. return;
  30421.  
  30422. this._currentSearchResultIndex = -1;
  30423. this._searchResults = [];
  30424. this._textEditor.markAndRevealRange(null);
  30425. },
  30426.  
  30427. hasSearchResults: function()
  30428. {
  30429. return this._searchResults.length > 0;
  30430. },
  30431.  
  30432. jumpToFirstSearchResult: function()
  30433. {
  30434. this.jumpToSearchResult(0);
  30435. },
  30436.  
  30437. jumpToLastSearchResult: function()
  30438. {
  30439. this.jumpToSearchResult(this._searchResults.length - 1);
  30440. },
  30441.  
  30442. jumpToNextSearchResult: function()
  30443. {
  30444. this.jumpToSearchResult(this._currentSearchResultIndex + 1);
  30445. },
  30446.  
  30447. jumpToPreviousSearchResult: function()
  30448. {
  30449. this.jumpToSearchResult(this._currentSearchResultIndex - 1);
  30450. },
  30451.  
  30452. showingFirstSearchResult: function()
  30453. {
  30454. return this._searchResults.length &&  this._currentSearchResultIndex === 0;
  30455. },
  30456.  
  30457. showingLastSearchResult: function()
  30458. {
  30459. return this._searchResults.length && this._currentSearchResultIndex === (this._searchResults.length - 1);
  30460. },
  30461.  
  30462. get currentSearchResultIndex()
  30463. {
  30464. return this._currentSearchResultIndex;
  30465. },
  30466.  
  30467. jumpToSearchResult: function(index)
  30468. {
  30469. if (!this.loaded || !this._searchResults.length)
  30470. return;
  30471. this._currentSearchResultIndex = (index + this._searchResults.length) % this._searchResults.length;
  30472. this._textEditor.markAndRevealRange(this._searchResults[this._currentSearchResultIndex]);
  30473. },
  30474.  
  30475.  
  30476. replaceSearchMatchWith: function(text)
  30477. {
  30478. var range = this._searchResults[this._currentSearchResultIndex];
  30479. if (!range)
  30480. return;
  30481. this._textEditor.markAndRevealRange(null);
  30482.  
  30483. this._isReplacing = true;
  30484. var newRange = this._textEditor.editRange(range, text);
  30485. delete this._isReplacing;
  30486.  
  30487. this._textEditor.setSelection(newRange.collapseToEnd());
  30488. },
  30489.  
  30490.  
  30491. replaceAllWith: function(query, replacement)
  30492. {
  30493. this._textEditor.markAndRevealRange(null);
  30494.  
  30495. var text = this._textEditor.text();
  30496. var range = this._textEditor.range();
  30497. text = text.replace(WebInspector.SourceFrame.createSearchRegex(query, "g"), replacement);
  30498.  
  30499. this._isReplacing = true;
  30500. this._textEditor.editRange(range, text);
  30501. delete this._isReplacing;
  30502. },
  30503.  
  30504. _collectRegexMatches: function(regexObject)
  30505. {
  30506. var ranges = [];
  30507. for (var i = 0; i < this._textEditor.linesCount; ++i) {
  30508. var line = this._textEditor.line(i);
  30509. var offset = 0;
  30510. do {
  30511. var match = regexObject.exec(line);
  30512. if (match) {
  30513. if (match[0].length)
  30514. ranges.push(new WebInspector.TextRange(i, offset + match.index, i, offset + match.index + match[0].length));
  30515. offset += match.index + 1;
  30516. line = line.substring(match.index + 1);
  30517. }
  30518. } while (match && line);
  30519. }
  30520. return ranges;
  30521. },
  30522.  
  30523. _addExistingMessagesToSource: function()
  30524. {
  30525. var length = this._messages.length;
  30526. for (var i = 0; i < length; ++i)
  30527. this.addMessageToSource(this._messages[i].line - 1, this._messages[i]);
  30528. },
  30529.  
  30530. addMessageToSource: function(lineNumber, msg)
  30531. {
  30532. if (lineNumber >= this._textEditor.linesCount)
  30533. lineNumber = this._textEditor.linesCount - 1;
  30534. if (lineNumber < 0)
  30535. lineNumber = 0;
  30536.  
  30537. var messageBubbleElement = this._messageBubbles[lineNumber];
  30538. if (!messageBubbleElement || messageBubbleElement.nodeType !== Node.ELEMENT_NODE || !messageBubbleElement.hasStyleClass("webkit-html-message-bubble")) {
  30539. messageBubbleElement = document.createElement("div");
  30540. messageBubbleElement.className = "webkit-html-message-bubble";
  30541. this._messageBubbles[lineNumber] = messageBubbleElement;
  30542. this._textEditor.addDecoration(lineNumber, messageBubbleElement);
  30543. }
  30544.  
  30545. var rowMessages = this._rowMessages[lineNumber];
  30546. if (!rowMessages) {
  30547. rowMessages = [];
  30548. this._rowMessages[lineNumber] = rowMessages;
  30549. }
  30550.  
  30551. for (var i = 0; i < rowMessages.length; ++i) {
  30552. if (rowMessages[i].consoleMessage.isEqual(msg)) {
  30553. rowMessages[i].repeatCount = msg.totalRepeatCount;
  30554. this._updateMessageRepeatCount(rowMessages[i]);
  30555. return;
  30556. }
  30557. }
  30558.  
  30559. var rowMessage = { consoleMessage: msg };
  30560. rowMessages.push(rowMessage);
  30561.  
  30562. var imageURL;
  30563. switch (msg.level) {
  30564. case WebInspector.ConsoleMessage.MessageLevel.Error:
  30565. messageBubbleElement.addStyleClass("webkit-html-error-message");
  30566. imageURL = "Images/errorIcon.png";
  30567. break;
  30568. case WebInspector.ConsoleMessage.MessageLevel.Warning:
  30569. messageBubbleElement.addStyleClass("webkit-html-warning-message");
  30570. imageURL = "Images/warningIcon.png";
  30571. break;
  30572. }
  30573.  
  30574. var messageLineElement = document.createElement("div");
  30575. messageLineElement.className = "webkit-html-message-line";
  30576. messageBubbleElement.appendChild(messageLineElement);
  30577.  
  30578.  
  30579. var image = document.createElement("img");
  30580. image.src = imageURL;
  30581. image.className = "webkit-html-message-icon";
  30582. messageLineElement.appendChild(image);
  30583. messageLineElement.appendChild(document.createTextNode(msg.message));
  30584.  
  30585. rowMessage.element = messageLineElement;
  30586. rowMessage.repeatCount = msg.totalRepeatCount;
  30587. this._updateMessageRepeatCount(rowMessage);
  30588. },
  30589.  
  30590. _updateMessageRepeatCount: function(rowMessage)
  30591. {
  30592. if (rowMessage.repeatCount < 2)
  30593. return;
  30594.  
  30595. if (!rowMessage.repeatCountElement) {
  30596. var repeatCountElement = document.createElement("span");
  30597. rowMessage.element.appendChild(repeatCountElement);
  30598. rowMessage.repeatCountElement = repeatCountElement;
  30599. }
  30600.  
  30601. rowMessage.repeatCountElement.textContent = WebInspector.UIString(" (repeated %d times)", rowMessage.repeatCount);
  30602. },
  30603.  
  30604. removeMessageFromSource: function(lineNumber, msg)
  30605. {
  30606. if (lineNumber >= this._textEditor.linesCount)
  30607. lineNumber = this._textEditor.linesCount - 1;
  30608. if (lineNumber < 0)
  30609. lineNumber = 0;
  30610.  
  30611. var rowMessages = this._rowMessages[lineNumber];
  30612. for (var i = 0; rowMessages && i < rowMessages.length; ++i) {
  30613. var rowMessage = rowMessages[i];
  30614. if (rowMessage.consoleMessage !== msg)
  30615. continue;
  30616.  
  30617. var messageLineElement = rowMessage.element;
  30618. var messageBubbleElement = messageLineElement.parentElement;
  30619. messageBubbleElement.removeChild(messageLineElement);
  30620. rowMessages.remove(rowMessage);
  30621. if (!rowMessages.length)
  30622. delete this._rowMessages[lineNumber];
  30623. if (!messageBubbleElement.childElementCount) {
  30624. this._textEditor.removeDecoration(lineNumber, messageBubbleElement);
  30625. delete this._messageBubbles[lineNumber];
  30626. }
  30627. break;
  30628. }
  30629. },
  30630.  
  30631. populateLineGutterContextMenu: function(contextMenu, lineNumber)
  30632. {
  30633. },
  30634.  
  30635. populateTextAreaContextMenu: function(contextMenu, lineNumber)
  30636. {
  30637. },
  30638.  
  30639. inheritScrollPositions: function(sourceFrame)
  30640. {
  30641. this._textEditor.inheritScrollPositions(sourceFrame._textEditor);
  30642. },
  30643.  
  30644.  
  30645. canEditSource: function()
  30646. {
  30647. return false;
  30648. },
  30649.  
  30650.  
  30651. commitEditing: function(text)
  30652. {
  30653. },
  30654.  
  30655.  
  30656. selectionChanged: function(textRange)
  30657. {
  30658. this.dispatchEventToListeners(WebInspector.SourceFrame.Events.SelectionChanged, textRange);
  30659. },
  30660.  
  30661.  
  30662. scrollChanged: function(lineNumber)
  30663. {
  30664. this.dispatchEventToListeners(WebInspector.SourceFrame.Events.ScrollChanged, lineNumber);
  30665. },
  30666.  
  30667. _handleKeyDown: function(e)
  30668. {
  30669. var shortcutKey = WebInspector.KeyboardShortcut.makeKeyFromEvent(e);
  30670. var handler = this._shortcuts[shortcutKey];
  30671. if (handler && handler())
  30672. e.consume(true);
  30673. },
  30674.  
  30675. _commitEditing: function()
  30676. {
  30677. if (this._textEditor.readOnly())
  30678. return false;
  30679.  
  30680. var content = this._textEditor.text();
  30681. this.commitEditing(content);
  30682. return true;
  30683. },
  30684.  
  30685. __proto__: WebInspector.View.prototype
  30686. }
  30687.  
  30688.  
  30689.  
  30690. WebInspector.TextEditorDelegateForSourceFrame = function(sourceFrame)
  30691. {
  30692. this._sourceFrame = sourceFrame;
  30693. }
  30694.  
  30695. WebInspector.TextEditorDelegateForSourceFrame.prototype = {
  30696. onTextChanged: function(oldRange, newRange)
  30697. {
  30698. this._sourceFrame.onTextChanged(oldRange, newRange);
  30699. },
  30700.  
  30701.  
  30702. selectionChanged: function(textRange)
  30703. {
  30704. this._sourceFrame.selectionChanged(textRange);
  30705. },
  30706.  
  30707.  
  30708. scrollChanged: function(lineNumber)
  30709. {
  30710. this._sourceFrame.scrollChanged(lineNumber);
  30711. },
  30712.  
  30713. populateLineGutterContextMenu: function(contextMenu, lineNumber)
  30714. {
  30715. this._sourceFrame.populateLineGutterContextMenu(contextMenu, lineNumber);
  30716. },
  30717.  
  30718. populateTextAreaContextMenu: function(contextMenu, lineNumber)
  30719. {
  30720. this._sourceFrame.populateTextAreaContextMenu(contextMenu, lineNumber);
  30721. },
  30722.  
  30723.  
  30724. createLink: function(hrefValue, isExternal)
  30725. {
  30726. var targetLocation = WebInspector.ParsedURL.completeURL(this._sourceFrame._url, hrefValue);
  30727. return WebInspector.linkifyURLAsNode(targetLocation || hrefValue, hrefValue, undefined, isExternal);
  30728. },
  30729.  
  30730. __proto__: WebInspector.TextEditorDelegate.prototype
  30731. }
  30732.  
  30733.  
  30734.  
  30735.  
  30736.  
  30737.  
  30738. WebInspector.ResourceView = function(resource)
  30739. {
  30740. WebInspector.View.call(this);
  30741. this.registerRequiredCSS("resourceView.css");
  30742.  
  30743. this.element.addStyleClass("resource-view");
  30744. this.resource = resource;
  30745. }
  30746.  
  30747. WebInspector.ResourceView.prototype = {
  30748. hasContent: function()
  30749. {
  30750. return false;
  30751. },
  30752.  
  30753. __proto__: WebInspector.View.prototype
  30754. }
  30755.  
  30756.  
  30757. WebInspector.ResourceView.hasTextContent = function(resource)
  30758. {
  30759. if (resource.type.isTextType())
  30760. return true; 
  30761. if (resource.type === WebInspector.resourceTypes.Other)
  30762. return resource.content && !resource.contentEncoded;
  30763. return false;
  30764. }
  30765.  
  30766.  
  30767. WebInspector.ResourceView.nonSourceViewForResource = function(resource)
  30768. {
  30769. switch (resource.type) {
  30770. case WebInspector.resourceTypes.Image:
  30771. return new WebInspector.ImageView(resource);
  30772. case WebInspector.resourceTypes.Font:
  30773. return new WebInspector.FontView(resource);
  30774. default:
  30775. return new WebInspector.ResourceView(resource);
  30776. }
  30777. }
  30778.  
  30779.  
  30780. WebInspector.ResourceSourceFrame = function(resource)
  30781. {
  30782. this._resource = resource;
  30783. WebInspector.SourceFrame.call(this, resource);
  30784. }
  30785.  
  30786. WebInspector.ResourceSourceFrame.prototype = {
  30787. get resource()
  30788. {
  30789. return this._resource;
  30790. },
  30791.  
  30792. populateTextAreaContextMenu: function(contextMenu, lineNumber)
  30793. {
  30794. contextMenu.appendApplicableItems(this._resource);
  30795. if (this._resource.request)
  30796. contextMenu.appendApplicableItems(this._resource.request);
  30797. },
  30798.  
  30799. __proto__: WebInspector.SourceFrame.prototype
  30800. }
  30801.  
  30802.  
  30803.  
  30804.  
  30805.  
  30806.  
  30807. WebInspector.FontView = function(resource)
  30808. {
  30809. WebInspector.ResourceView.call(this, resource);
  30810.  
  30811. this.element.addStyleClass("font");
  30812. }
  30813.  
  30814. WebInspector.FontView._fontPreviewLines = [ "ABCDEFGHIJKLM", "NOPQRSTUVWXYZ", "abcdefghijklm", "nopqrstuvwxyz", "1234567890" ];
  30815.  
  30816. WebInspector.FontView._fontId = 0;
  30817.  
  30818. WebInspector.FontView._measureFontSize = 50;
  30819.  
  30820. WebInspector.FontView.prototype = {
  30821. hasContent: function()
  30822. {
  30823. return true;
  30824. },
  30825.  
  30826. _createContentIfNeeded: function()
  30827. {
  30828. if (this.fontPreviewElement)
  30829. return;
  30830.  
  30831. var uniqueFontName = "WebInspectorFontPreview" + (++WebInspector.FontView._fontId);
  30832.  
  30833. this.fontStyleElement = document.createElement("style");
  30834. this.fontStyleElement.textContent = "@font-face { font-family: \"" + uniqueFontName + "\"; src: url(" + this.resource.url + "); }";
  30835. document.head.appendChild(this.fontStyleElement);
  30836.  
  30837. var fontPreview = document.createElement("div");
  30838. for (var i = 0; i < WebInspector.FontView._fontPreviewLines.length; ++i) {
  30839. if (i > 0)
  30840. fontPreview.appendChild(document.createElement("br"));
  30841. fontPreview.appendChild(document.createTextNode(WebInspector.FontView._fontPreviewLines[i]));
  30842. }
  30843. this.fontPreviewElement = fontPreview.cloneNode(true);
  30844. this.fontPreviewElement.style.setProperty("font-family", uniqueFontName);
  30845. this.fontPreviewElement.style.setProperty("visibility", "hidden");
  30846.  
  30847. this._dummyElement = fontPreview;
  30848. this._dummyElement.style.visibility = "hidden";
  30849. this._dummyElement.style.zIndex = "-1";
  30850. this._dummyElement.style.display = "inline";
  30851. this._dummyElement.style.position = "absolute";
  30852. this._dummyElement.style.setProperty("font-family", uniqueFontName);
  30853. this._dummyElement.style.setProperty("font-size", WebInspector.FontView._measureFontSize + "px");
  30854.  
  30855. this.element.appendChild(this.fontPreviewElement);
  30856. },
  30857.  
  30858. wasShown: function()
  30859. {
  30860. this._createContentIfNeeded();
  30861.  
  30862. this.updateFontPreviewSize();
  30863. },
  30864.  
  30865. onResize: function()
  30866. {
  30867. if (this._inResize)
  30868. return;
  30869.  
  30870. this._inResize = true;
  30871. try {
  30872. this.updateFontPreviewSize();
  30873. } finally {
  30874. delete this._inResize;
  30875. }
  30876. },
  30877.  
  30878. _measureElement: function()
  30879. {
  30880. this.element.appendChild(this._dummyElement);
  30881. var result = { width: this._dummyElement.offsetWidth, height: this._dummyElement.offsetHeight };
  30882. this.element.removeChild(this._dummyElement);
  30883.  
  30884. return result;
  30885. },
  30886.  
  30887. updateFontPreviewSize: function()
  30888. {
  30889. if (!this.fontPreviewElement || !this.isShowing())
  30890. return;
  30891.  
  30892. this.fontPreviewElement.style.removeProperty("visibility");
  30893. var dimension = this._measureElement();
  30894.  
  30895. const height = dimension.height;
  30896. const width = dimension.width;
  30897.  
  30898.  
  30899. const containerWidth = this.element.offsetWidth - 50;
  30900. const containerHeight = this.element.offsetHeight - 30;
  30901.  
  30902. if (!height || !width || !containerWidth || !containerHeight) {
  30903. this.fontPreviewElement.style.removeProperty("font-size");
  30904. return;
  30905. }
  30906.  
  30907. var widthRatio = containerWidth / width;
  30908. var heightRatio = containerHeight / height;
  30909. var finalFontSize = Math.floor(WebInspector.FontView._measureFontSize * Math.min(widthRatio, heightRatio)) - 2;
  30910.  
  30911. this.fontPreviewElement.style.setProperty("font-size", finalFontSize + "px", null);
  30912. },
  30913.  
  30914. __proto__: WebInspector.ResourceView.prototype
  30915. }
  30916.  
  30917.  
  30918.  
  30919.  
  30920.  
  30921.  
  30922. WebInspector.ImageView = function(resource)
  30923. {
  30924. WebInspector.ResourceView.call(this, resource);
  30925.  
  30926. this.element.addStyleClass("image");
  30927. }
  30928.  
  30929. WebInspector.ImageView.prototype = {
  30930. hasContent: function()
  30931. {
  30932. return true;
  30933. },
  30934.  
  30935. wasShown: function()
  30936. {
  30937. this._createContentIfNeeded();
  30938. },
  30939.  
  30940. _createContentIfNeeded: function()
  30941. {
  30942. if (this._container)
  30943. return;
  30944.  
  30945. var imageContainer = document.createElement("div");
  30946. imageContainer.className = "image";
  30947. this.element.appendChild(imageContainer);
  30948.  
  30949. var imagePreviewElement = document.createElement("img");
  30950. imagePreviewElement.addStyleClass("resource-image-view");
  30951. imageContainer.appendChild(imagePreviewElement);
  30952. imagePreviewElement.addEventListener("contextmenu", this._contextMenu.bind(this), true);
  30953.  
  30954. this._container = document.createElement("div");
  30955. this._container.className = "info";
  30956. this.element.appendChild(this._container);
  30957.  
  30958. var imageNameElement = document.createElement("h1");
  30959. imageNameElement.className = "title";
  30960. imageNameElement.textContent = this.resource.displayName;
  30961. this._container.appendChild(imageNameElement);
  30962.  
  30963. var infoListElement = document.createElement("dl");
  30964. infoListElement.className = "infoList";
  30965.  
  30966. this.resource.populateImageSource(imagePreviewElement);
  30967.  
  30968. function onImageLoad()
  30969. {
  30970. var content = this.resource.content;
  30971. if (content)
  30972. var resourceSize = this._base64ToSize(content);
  30973. else
  30974. var resourceSize = this.resource.resourceSize;
  30975.  
  30976. var imageProperties = [
  30977. { name: WebInspector.UIString("Dimensions"), value: WebInspector.UIString("%d ├ù %d", imagePreviewElement.naturalWidth, imagePreviewElement.naturalHeight) },
  30978. { name: WebInspector.UIString("File size"), value: Number.bytesToString(resourceSize) },
  30979. { name: WebInspector.UIString("MIME type"), value: this.resource.mimeType }
  30980. ];
  30981.  
  30982. infoListElement.removeChildren();
  30983. for (var i = 0; i < imageProperties.length; ++i) {
  30984. var dt = document.createElement("dt");
  30985. dt.textContent = imageProperties[i].name;
  30986. infoListElement.appendChild(dt);
  30987. var dd = document.createElement("dd");
  30988. dd.textContent = imageProperties[i].value;
  30989. infoListElement.appendChild(dd);
  30990. }
  30991. var dt = document.createElement("dt");
  30992. dt.textContent = WebInspector.UIString("URL");
  30993. infoListElement.appendChild(dt);
  30994. var dd = document.createElement("dd");
  30995. var externalResource = true;
  30996. dd.appendChild(WebInspector.linkifyURLAsNode(this.resource.url, undefined, undefined, externalResource));
  30997. infoListElement.appendChild(dd);
  30998.  
  30999. this._container.appendChild(infoListElement);
  31000. }
  31001. imagePreviewElement.addEventListener("load", onImageLoad.bind(this), false);
  31002. },
  31003.  
  31004. _base64ToSize: function(content)
  31005. {
  31006. if (!content.length)
  31007. return 0;
  31008. var size = (content.length || 0) * 3 / 4;
  31009. if (content.length > 0 && content[content.length - 1] === "=")
  31010. size--;
  31011. if (content.length > 1 && content[content.length - 2] === "=")
  31012. size--;
  31013. return size;
  31014. },
  31015.  
  31016. _contextMenu: function(event)
  31017. {
  31018. var contextMenu = new WebInspector.ContextMenu(event);
  31019. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy image URL" : "Copy Image URL"), this._copyImageURL.bind(this));
  31020. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Open image in new tab" : "Open Image in New Tab"), this._openInNewTab.bind(this));
  31021. contextMenu.show();
  31022. },
  31023.  
  31024. _copyImageURL: function(event)
  31025. {
  31026. InspectorFrontendHost.copyText(this.resource.url);
  31027. },
  31028.  
  31029. _openInNewTab: function(event)
  31030. {
  31031. InspectorFrontendHost.openInNewTab(this.resource.url);
  31032. },
  31033.  
  31034. __proto__: WebInspector.ResourceView.prototype
  31035. }
  31036.  
  31037.  
  31038.  
  31039.  
  31040.  
  31041.  
  31042. WebInspector.SplitView = function(isVertical, sidebarSizeSettingName, defaultSidebarSize)
  31043. {
  31044. WebInspector.View.call(this);
  31045. this._isVertical = isVertical;
  31046.  
  31047. this.registerRequiredCSS("splitView.css");
  31048.  
  31049. this.element.className = "split-view";
  31050.  
  31051. this._firstElement = document.createElement("div");
  31052. this._firstElement.className = "split-view-contents split-view-contents-" + (isVertical ? "vertical" : "horizontal");
  31053. if (isVertical)
  31054. this._firstElement.style.left = 0;
  31055. else
  31056. this._firstElement.style.top = 0;
  31057. this.element.appendChild(this._firstElement);
  31058.  
  31059. this._secondElement = document.createElement("div");
  31060. this._secondElement.className = "split-view-contents split-view-contents-" + (isVertical ? "vertical" : "horizontal");
  31061. if (isVertical)
  31062. this._secondElement.style.right = 0;
  31063. else
  31064. this._secondElement.style.bottom = 0;
  31065. this.element.appendChild(this._secondElement);
  31066.  
  31067. this._resizerElement = document.createElement("div");
  31068. this._resizerElement.className = "split-view-resizer split-view-resizer-" + (isVertical ? "vertical" : "horizontal");
  31069. this.installResizer(this._resizerElement);
  31070. this._resizable = true;
  31071. this.element.appendChild(this._resizerElement);
  31072.  
  31073. defaultSidebarSize = defaultSidebarSize || 200;
  31074. this._savedSidebarSize = defaultSidebarSize;
  31075.  
  31076. this._sidebarSizeSettingName = sidebarSizeSettingName;
  31077. if (this._sidebarSizeSettingName)
  31078. WebInspector.settings[this._sidebarSizeSettingName] = WebInspector.settings.createSetting(this._sidebarSizeSettingName, undefined);
  31079.  
  31080. this._secondIsSidebar = true;
  31081. }
  31082.  
  31083. WebInspector.SplitView.prototype = {
  31084.  
  31085. firstElement: function()
  31086. {
  31087. return this._firstElement;
  31088. },
  31089.  
  31090.  
  31091. secondElement: function()
  31092. {
  31093. return this._secondElement;
  31094. },
  31095.  
  31096.  
  31097. setSecondIsSidebar: function(secondIsSidebar)
  31098. {
  31099. this._secondIsSidebar = secondIsSidebar;
  31100. },
  31101.  
  31102.  
  31103. resizerElement: function()
  31104. {
  31105. return this._resizerElement;
  31106. },
  31107.  
  31108. showOnlyFirst: function()
  31109. {
  31110. this._showOnly(this._firstElement, this._secondElement);
  31111. },
  31112.  
  31113. showOnlySecond: function()
  31114. {
  31115. this._showOnly(this._secondElement, this._firstElement);
  31116. },
  31117.  
  31118.  
  31119. _showOnly: function(sideA, sideB)
  31120. {
  31121. sideA.removeStyleClass("hidden");
  31122. sideA.addStyleClass("maximized");
  31123. sideB.addStyleClass("hidden");
  31124. sideB.removeStyleClass("maximized");
  31125. this._removeAllLayoutProperties();
  31126.  
  31127. this._firstElement.style.right = 0;
  31128. this._firstElement.style.bottom = 0;
  31129. this._firstElement.style.width = "100%";
  31130. this._firstElement.style.height = "100%";
  31131.  
  31132. this._secondElement.style.left = 0;
  31133. this._secondElement.style.top = 0;
  31134. this._secondElement.style.width = "100%";
  31135. this._secondElement.style.height = "100%";
  31136.  
  31137. this._isShowingOne = true;
  31138. this.setResizable(false);
  31139. this.doResize();
  31140. },
  31141.  
  31142. _removeAllLayoutProperties: function()
  31143. {
  31144. this._firstElement.style.removeProperty("right");
  31145. this._firstElement.style.removeProperty("bottom");
  31146. this._firstElement.style.removeProperty("width");
  31147. this._firstElement.style.removeProperty("height");
  31148.  
  31149. this._secondElement.style.removeProperty("left");
  31150. this._secondElement.style.removeProperty("top");
  31151. this._secondElement.style.removeProperty("width");
  31152. this._secondElement.style.removeProperty("height");
  31153. },
  31154.  
  31155. showBoth: function()
  31156. {
  31157. this._isShowingOne = false;
  31158. this._firstElement.removeStyleClass("hidden");
  31159. this._firstElement.removeStyleClass("maximized");
  31160. this._secondElement.removeStyleClass("hidden");
  31161. this._secondElement.removeStyleClass("maximized");
  31162.  
  31163.  
  31164. delete this._sidebarSize;
  31165. this.setSidebarSize(this._lastSidebarSize());
  31166.  
  31167. this.setResizable(true);
  31168. this.doResize();
  31169. },
  31170.  
  31171.  
  31172. setResizable: function(resizable)
  31173. {
  31174. if (this._resizable === resizable)
  31175. return;
  31176. this._resizable = resizable;
  31177. if (resizable)
  31178. this._resizerElement.removeStyleClass("hidden");
  31179. else
  31180. this._resizerElement.addStyleClass("hidden");
  31181. },
  31182.  
  31183.  
  31184. setSidebarSize: function(size)
  31185. {
  31186. if (this._sidebarSize === size)
  31187. return;
  31188.  
  31189. size = this.applyConstraints(size);
  31190. this._innerSetSidebarSize(size);
  31191. this._saveSidebarSize(size);
  31192. },
  31193.  
  31194.  
  31195. sidebarSize: function()
  31196. {
  31197. return this._sidebarSize;
  31198. },
  31199.  
  31200.  
  31201. totalSize: function()
  31202. {
  31203. return this._totalSize;
  31204. },
  31205.  
  31206.  
  31207. _innerSetSidebarSize: function(size)
  31208. {
  31209. if (this._isShowingOne)
  31210. return;
  31211.  
  31212. this._removeAllLayoutProperties();
  31213.  
  31214. if (this._isVertical) {
  31215. var resizerWidth = this._resizerElement.offsetWidth;
  31216. if (this._secondIsSidebar) {
  31217. this._firstElement.style.right = size + "px";
  31218. this._secondElement.style.width = size + "px";
  31219. this._resizerElement.style.right = size - resizerWidth / 2 + "px";
  31220. } else {
  31221. this._firstElement.style.width = size + "px";;
  31222. this._secondElement.style.left = size + "px";;
  31223. this._resizerElement.style.left = size - resizerWidth / 2 + "px";
  31224. }
  31225. } else {
  31226. var resizerHeight = this._resizerElement.offsetHeight;
  31227.  
  31228. if (this._secondIsSidebar) {
  31229. this._firstElement.style.bottom = size + "px";;
  31230. this._secondElement.style.height = size + "px";;
  31231. this._resizerElement.style.bottom = size - resizerHeight / 2 + "px";
  31232. } else {
  31233. this._firstElement.style.height = size + "px";;
  31234. this._secondElement.style.top = size + "px";;
  31235. this._resizerElement.style.top = size - resizerHeight / 2 + "px";
  31236. }
  31237. }
  31238.  
  31239. this._sidebarSize = size;
  31240. this.doResize();
  31241. },
  31242.  
  31243.  
  31244. applyConstraints: function(size)
  31245. {
  31246. const minSize = 20;
  31247. size = Math.max(size, minSize);
  31248. if (this._totalSize - size < minSize)
  31249. size = this._totalSize - minSize;
  31250. return size;
  31251. },
  31252.  
  31253. wasShown: function()
  31254. {
  31255. this._totalSize = this._isVertical ? this.element.offsetWidth : this.element.offsetHeight;
  31256. this.setSidebarSize(this._lastSidebarSize());
  31257. },
  31258.  
  31259. onResize: function()
  31260. {
  31261. var oldTotalSize = this._totalSize;
  31262. this._totalSize = this._isVertical ? this.element.offsetWidth : this.element.offsetHeight;
  31263. },
  31264.  
  31265.  
  31266. _startResizerDragging: function(event)
  31267. {
  31268. if (!this._resizable)
  31269. return false;
  31270.  
  31271. this._dragOffset = (this._secondIsSidebar ? this._totalSize - this._sidebarSize : this._sidebarSize) - (this._isVertical ? event.pageX : event.pageY);
  31272. return true;
  31273. },
  31274.  
  31275.  
  31276. _resizerDragging: function(event)
  31277. {
  31278. var newOffset = (this._isVertical ? event.pageX : event.pageY) + this._dragOffset;
  31279. var newSize = (this._secondIsSidebar ? this._totalSize - newOffset : newOffset);
  31280. this.setSidebarSize(newSize);
  31281. event.preventDefault();
  31282. },
  31283.  
  31284.  
  31285. _endResizerDragging: function(event)
  31286. {
  31287. delete this._dragOffset;
  31288. },
  31289.  
  31290.  
  31291. installResizer: function(resizerElement)
  31292. {
  31293. WebInspector.installDragHandle(resizerElement, this._startResizerDragging.bind(this), this._resizerDragging.bind(this), this._endResizerDragging.bind(this), this._isVertical ? "ew-resize" : "ns-resize");
  31294. },
  31295.  
  31296.  
  31297. _lastSidebarSize: function()
  31298. {
  31299. return this._sidebarSizeSettingName ? WebInspector.settings[this._sidebarSizeSettingName].get() || this._savedSidebarSize : this._savedSidebarSize;
  31300. },
  31301.  
  31302.  
  31303. _saveSidebarSize: function(size)
  31304. {
  31305. this._savedSidebarSize = size;
  31306. if (!this._sidebarSizeSettingName)
  31307. return;
  31308.  
  31309. WebInspector.settings[this._sidebarSizeSettingName].set(this._savedSidebarSize);
  31310. },
  31311.  
  31312. __proto__: WebInspector.View.prototype
  31313. }
  31314.  
  31315.  
  31316.  
  31317.  
  31318.  
  31319.  
  31320. WebInspector.SidebarView = function(sidebarPosition, sidebarWidthSettingName, defaultSidebarWidth)
  31321. {
  31322. WebInspector.SplitView.call(this, true, sidebarWidthSettingName, defaultSidebarWidth || 200);
  31323.  
  31324. this._leftElement = this.firstElement();
  31325. this._rightElement = this.secondElement();
  31326.  
  31327. this._minimumSidebarWidth = Preferences.minSidebarWidth;
  31328. this._minimumMainWidthPercent = 50;
  31329.  
  31330. this._mainElementHidden = false;
  31331. this._sidebarElementHidden = false;
  31332.  
  31333. this._innerSetSidebarPosition(sidebarPosition || WebInspector.SidebarView.SidebarPosition.Left);
  31334. this.setSecondIsSidebar(sidebarPosition !== WebInspector.SidebarView.SidebarPosition.Left);
  31335. }
  31336.  
  31337. WebInspector.SidebarView.EventTypes = {
  31338. Resized: "Resized"
  31339. }
  31340.  
  31341.  
  31342. WebInspector.SidebarView.SidebarPosition = {
  31343. Left: "Left",
  31344. Right: "Right"
  31345. }
  31346.  
  31347. WebInspector.SidebarView.prototype = {
  31348.  
  31349. _hasLeftSidebar: function()
  31350. {
  31351. return this._sidebarPosition === WebInspector.SidebarView.SidebarPosition.Left;
  31352. },
  31353.  
  31354.  
  31355. get mainElement()
  31356. {
  31357. return this._hasLeftSidebar() ? this._rightElement : this._leftElement;
  31358. },
  31359.  
  31360.  
  31361. get sidebarElement()
  31362. {
  31363. return this._hasLeftSidebar() ? this._leftElement : this._rightElement;
  31364. },
  31365.  
  31366.  
  31367. _innerSetSidebarPosition: function(sidebarPosition)
  31368. {
  31369. this._sidebarPosition = sidebarPosition;
  31370.  
  31371. if (this._hasLeftSidebar()) {
  31372. this._leftElement.addStyleClass("split-view-sidebar-left");
  31373. this._rightElement.removeStyleClass("split-view-sidebar-right");
  31374. } else {
  31375. this._rightElement.addStyleClass("split-view-sidebar-right");
  31376. this._leftElement.removeStyleClass("split-view-sidebar-left");
  31377. }
  31378. },
  31379.  
  31380.  
  31381. setMinimumSidebarWidth: function(width)
  31382. {
  31383. this._minimumSidebarWidth = width;
  31384. },
  31385.  
  31386.  
  31387. setMinimumMainWidthPercent: function(widthPercent)
  31388. {
  31389. this._minimumMainWidthPercent = widthPercent;
  31390. },
  31391.  
  31392.  
  31393. setSidebarWidth: function(width)
  31394. {
  31395. this.setSidebarSize(width);
  31396. },
  31397.  
  31398.  
  31399. sidebarWidth: function()
  31400. {
  31401. return this.sidebarSize();
  31402. },
  31403.  
  31404. onResize: function()
  31405. {
  31406. WebInspector.SplitView.prototype.onResize.call(this);
  31407. this.dispatchEventToListeners(WebInspector.SidebarView.EventTypes.Resized, this.sidebarWidth());
  31408. },
  31409.  
  31410.  
  31411. applyConstraints: function(size)
  31412. {
  31413. return Number.constrain(size, this._minimumSidebarWidth, this.element.offsetWidth * (100 - this._minimumMainWidthPercent) / 100);
  31414. },
  31415.  
  31416. hideMainElement: function()
  31417. {
  31418. if (this._hasLeftSidebar())
  31419. this.showOnlyFirst();
  31420. else
  31421. this.showOnlySecond();
  31422. },
  31423.  
  31424. showMainElement: function()
  31425. {
  31426. this.showBoth();
  31427. },
  31428.  
  31429. hideSidebarElement: function()
  31430. {
  31431. if (this._hasLeftSidebar())
  31432. this.showOnlySecond();
  31433. else
  31434. this.showOnlyFirst();
  31435. },
  31436.  
  31437. showSidebarElement: function()
  31438. {
  31439. this.showBoth();
  31440. },
  31441.  
  31442.  
  31443. elementsToRestoreScrollPositionsFor: function()
  31444. {
  31445. return [ this.mainElement, this.sidebarElement ];
  31446. },
  31447.  
  31448. __proto__: WebInspector.SplitView.prototype
  31449. }
  31450.  
  31451.  
  31452.  
  31453.  
  31454.  
  31455.  
  31456. WebInspector.ConsolePanel = function()
  31457. {
  31458. WebInspector.Panel.call(this, "console");
  31459.  
  31460. WebInspector.consoleView.addEventListener(WebInspector.ConsoleView.Events.EntryAdded, this._consoleMessageAdded, this);
  31461. WebInspector.consoleView.addEventListener(WebInspector.ConsoleView.Events.ConsoleCleared, this._consoleCleared, this);
  31462. this._view = WebInspector.consoleView;
  31463. }
  31464.  
  31465. WebInspector.ConsolePanel.prototype = {
  31466. get statusBarItems()
  31467. {
  31468. return this._view.statusBarItems;
  31469. },
  31470.  
  31471. wasShown: function()
  31472. {
  31473. WebInspector.Panel.prototype.wasShown.call(this);
  31474. if (WebInspector.drawer.visible) {
  31475. WebInspector.drawer.hide(WebInspector.Drawer.AnimationType.Immediately);
  31476. this._drawerWasVisible = true;
  31477. }
  31478. this._view.show(this.element);
  31479. },
  31480.  
  31481. willHide: function()
  31482. {
  31483. if (this._drawerWasVisible) {
  31484. WebInspector.drawer.show(this._view, WebInspector.Drawer.AnimationType.Immediately);
  31485. delete this._drawerWasVisible;
  31486. }
  31487. WebInspector.Panel.prototype.willHide.call(this);
  31488. },
  31489.  
  31490. searchCanceled: function()
  31491. {
  31492. this._clearCurrentSearchResultHighlight();
  31493. delete this._searchResults;
  31494. delete this._searchRegex;
  31495. },
  31496.  
  31497.  
  31498. performSearch: function(query)
  31499. {
  31500. WebInspector.searchController.updateSearchMatchesCount(0, this);
  31501. this.searchCanceled();
  31502. this._searchRegex = createPlainTextSearchRegex(query, "gi");
  31503.  
  31504. this._searchResults = [];
  31505. var messages = WebInspector.consoleView.messages;
  31506. for (var i = 0; i < messages.length; i++) {
  31507. if (messages[i].matchesRegex(this._searchRegex)) {
  31508. this._searchResults.push(messages[i]);
  31509. this._searchRegex.lastIndex = 0;
  31510. }
  31511. }
  31512. WebInspector.searchController.updateSearchMatchesCount(this._searchResults.length, this);
  31513. this._currentSearchResultIndex = -1;
  31514. if (this._searchResults.length)
  31515. this._jumpToSearchResult(0);
  31516. },
  31517.  
  31518. jumpToNextSearchResult: function()
  31519. {
  31520. if (!this._searchResults || !this._searchResults.length)
  31521. return;
  31522. this._jumpToSearchResult((this._currentSearchResultIndex + 1) % this._searchResults.length);
  31523. },
  31524.  
  31525. jumpToPreviousSearchResult: function()
  31526. {
  31527. if (!this._searchResults || !this._searchResults.length)
  31528. return;
  31529. var index = this._currentSearchResultIndex - 1;
  31530. if (index === -1)
  31531. index = this._searchResults.length - 1;
  31532. this._jumpToSearchResult(index);
  31533. return true;
  31534. },
  31535.  
  31536. _clearCurrentSearchResultHighlight: function()
  31537. {
  31538. if (!this._searchResults)
  31539. return;
  31540. var highlightedMessage = this._searchResults[this._currentSearchResultIndex];
  31541. if (highlightedMessage)
  31542. highlightedMessage.clearHighlight();
  31543. this._currentSearchResultIndex = -1;
  31544. },
  31545.  
  31546. _jumpToSearchResult: function(index)
  31547. {
  31548. this._clearCurrentSearchResultHighlight();
  31549. this._currentSearchResultIndex = index;
  31550. WebInspector.searchController.updateCurrentMatchIndex(this._currentSearchResultIndex, this);
  31551. this._searchResults[index].highlightSearchResults(this._searchRegex);
  31552. },
  31553.  
  31554. _consoleMessageAdded: function(event)
  31555. {
  31556. if (!this._searchRegex || !this.isShowing())
  31557. return;
  31558. var message = event.data;
  31559. this._searchRegex.lastIndex = 0;
  31560. if (message.matchesRegex(this._searchRegex)) {
  31561. this._searchResults.push(message);
  31562. WebInspector.searchController.updateSearchMatchesCount(this._searchResults.length, this);
  31563. }
  31564. },
  31565.  
  31566. _consoleCleared: function()
  31567. {
  31568. if (!this._searchResults)
  31569. return;
  31570. this._clearCurrentSearchResultHighlight();
  31571. this._searchResults.length = 0;
  31572. if (this.isShowing())
  31573. WebInspector.searchController.updateSearchMatchesCount(0, this);
  31574. },
  31575.  
  31576. __proto__: WebInspector.Panel.prototype
  31577. }
  31578.  
  31579.  
  31580.  
  31581.  
  31582.  
  31583. function defineCommonExtensionSymbols(apiPrivate)
  31584. {
  31585. if (!apiPrivate.audits)
  31586. apiPrivate.audits = {};
  31587. apiPrivate.audits.Severity = {
  31588. Info: "info",
  31589. Warning: "warning",
  31590. Severe: "severe"
  31591. };
  31592.  
  31593. if (!apiPrivate.console)
  31594. apiPrivate.console = {};
  31595. apiPrivate.console.Severity = {
  31596. Tip: "tip",
  31597. Debug: "debug",
  31598. Log: "log",
  31599. Warning: "warning",
  31600. Error: "error"
  31601. };
  31602.  
  31603. if (!apiPrivate.panels)
  31604. apiPrivate.panels = {};
  31605. apiPrivate.panels.SearchAction = {
  31606. CancelSearch: "cancelSearch",
  31607. PerformSearch: "performSearch",
  31608. NextSearchResult: "nextSearchResult",
  31609. PreviousSearchResult: "previousSearchResult"
  31610. };
  31611.  
  31612. apiPrivate.Events = {
  31613. AuditStarted: "audit-started-",
  31614. ButtonClicked: "button-clicked-",
  31615. ConsoleMessageAdded: "console-message-added",
  31616. ElementsPanelObjectSelected: "panel-objectSelected-elements",
  31617. NetworkRequestFinished: "network-request-finished",
  31618. Reset: "reset",
  31619. OpenResource: "open-resource",
  31620. PanelSearch: "panel-search-",
  31621. Reload: "Reload",
  31622. ResourceAdded: "resource-added",
  31623. ResourceContentCommitted: "resource-content-committed",
  31624. TimelineEventRecorded: "timeline-event-recorded",
  31625. ViewShown: "view-shown-",
  31626. ViewHidden: "view-hidden-"
  31627. };
  31628.  
  31629. apiPrivate.Commands = {
  31630. AddAuditCategory: "addAuditCategory",
  31631. AddAuditResult: "addAuditResult",
  31632. AddConsoleMessage: "addConsoleMessage",
  31633. AddRequestHeaders: "addRequestHeaders",
  31634. CreatePanel: "createPanel",
  31635. CreateSidebarPane: "createSidebarPane",
  31636. CreateStatusBarButton: "createStatusBarButton",
  31637. EvaluateOnInspectedPage: "evaluateOnInspectedPage",
  31638. GetConsoleMessages: "getConsoleMessages",
  31639. GetHAR: "getHAR",
  31640. GetPageResources: "getPageResources",
  31641. GetRequestContent: "getRequestContent",
  31642. GetResourceContent: "getResourceContent",
  31643. Subscribe: "subscribe",
  31644. SetOpenResourceHandler: "setOpenResourceHandler",
  31645. SetResourceContent: "setResourceContent",
  31646. SetSidebarContent: "setSidebarContent",
  31647. SetSidebarHeight: "setSidebarHeight",
  31648. SetSidebarPage: "setSidebarPage",
  31649. ShowPanel: "showPanel",
  31650. StopAuditCategoryRun: "stopAuditCategoryRun",
  31651. Unsubscribe: "unsubscribe",
  31652. UpdateAuditProgress: "updateAuditProgress",
  31653. UpdateButton: "updateButton",
  31654. InspectedURLChanged: "inspectedURLChanged"
  31655. };
  31656. }
  31657.  
  31658. function injectedExtensionAPI(injectedScriptId)
  31659. {
  31660.  
  31661. var apiPrivate = {};
  31662.  
  31663. defineCommonExtensionSymbols(apiPrivate);
  31664.  
  31665. var commands = apiPrivate.Commands;
  31666. var events = apiPrivate.Events;
  31667. var userAction = false;
  31668.  
  31669.  
  31670.  
  31671.  
  31672.  
  31673.  
  31674.  
  31675.  
  31676. function EventSinkImpl(type, customDispatch)
  31677. {
  31678. this._type = type;
  31679. this._listeners = [];
  31680. this._customDispatch = customDispatch;
  31681. }
  31682.  
  31683. EventSinkImpl.prototype = {
  31684. addListener: function(callback)
  31685. {
  31686. if (typeof callback !== "function")
  31687. throw "addListener: callback is not a function";
  31688. if (this._listeners.length === 0)
  31689. extensionServer.sendRequest({ command: commands.Subscribe, type: this._type });
  31690. this._listeners.push(callback);
  31691. extensionServer.registerHandler("notify-" + this._type, this._dispatch.bind(this));
  31692. },
  31693.  
  31694. removeListener: function(callback)
  31695. {
  31696. var listeners = this._listeners;
  31697.  
  31698. for (var i = 0; i < listeners.length; ++i) {
  31699. if (listeners[i] === callback) {
  31700. listeners.splice(i, 1);
  31701. break;
  31702. }
  31703. }
  31704. if (this._listeners.length === 0)
  31705. extensionServer.sendRequest({ command: commands.Unsubscribe, type: this._type });
  31706. },
  31707.  
  31708. _fire: function()
  31709. {
  31710. var listeners = this._listeners.slice();
  31711. for (var i = 0; i < listeners.length; ++i)
  31712. listeners[i].apply(null, arguments);
  31713. },
  31714.  
  31715. _dispatch: function(request)
  31716. {
  31717. if (this._customDispatch)
  31718. this._customDispatch.call(this, request);
  31719. else
  31720. this._fire.apply(this, request.arguments);
  31721. }
  31722. }
  31723.  
  31724.  
  31725. function InspectorExtensionAPI()
  31726. {
  31727. this.audits = new Audits();
  31728. this.inspectedWindow = new InspectedWindow();
  31729. this.panels = new Panels();
  31730. this.network = new Network();
  31731. defineDeprecatedProperty(this, "webInspector", "resources", "network");
  31732. this.timeline = new Timeline();
  31733. this.console = new ConsoleAPI();
  31734.  
  31735. this.onReset = new EventSink(events.Reset);
  31736. }
  31737.  
  31738.  
  31739. InspectorExtensionAPI.prototype = {
  31740. log: function(message)
  31741. {
  31742. extensionServer.sendRequest({ command: commands.Log, message: message });
  31743. }
  31744. }
  31745.  
  31746.  
  31747. function ConsoleAPI()
  31748. {
  31749. this.onMessageAdded = new EventSink(events.ConsoleMessageAdded);
  31750. }
  31751.  
  31752. ConsoleAPI.prototype = {
  31753. getMessages: function(callback)
  31754. {
  31755. extensionServer.sendRequest({ command: commands.GetConsoleMessages }, callback);
  31756. },
  31757.  
  31758. addMessage: function(severity, text, url, line)
  31759. {
  31760. extensionServer.sendRequest({ command: commands.AddConsoleMessage, severity: severity, text: text, url: url, line: line });
  31761. },
  31762.  
  31763. get Severity()
  31764. {
  31765. return apiPrivate.console.Severity;
  31766. }
  31767. }
  31768.  
  31769.  
  31770. function Network()
  31771. {
  31772. function dispatchRequestEvent(message)
  31773. {
  31774. var request = message.arguments[1];
  31775. request.__proto__ = new Request(message.arguments[0]);
  31776. this._fire(request);
  31777. }
  31778. this.onRequestFinished = new EventSink(events.NetworkRequestFinished, dispatchRequestEvent);
  31779. defineDeprecatedProperty(this, "network", "onFinished", "onRequestFinished");
  31780. this.onNavigated = new EventSink(events.InspectedURLChanged);
  31781. }
  31782.  
  31783. Network.prototype = {
  31784. getHAR: function(callback)
  31785. {
  31786. function callbackWrapper(result)
  31787. {
  31788. var entries = (result && result.entries) || [];
  31789. for (var i = 0; i < entries.length; ++i) {
  31790. entries[i].__proto__ = new Request(entries[i]._requestId);
  31791. delete entries[i]._requestId;
  31792. }
  31793. callback(result);
  31794. }
  31795. return extensionServer.sendRequest({ command: commands.GetHAR }, callback && callbackWrapper);
  31796. },
  31797.  
  31798. addRequestHeaders: function(headers)
  31799. {
  31800. return extensionServer.sendRequest({ command: commands.AddRequestHeaders, headers: headers, extensionId: window.location.hostname });
  31801. }
  31802. }
  31803.  
  31804.  
  31805. function RequestImpl(id)
  31806. {
  31807. this._id = id;
  31808. }
  31809.  
  31810. RequestImpl.prototype = {
  31811. getContent: function(callback)
  31812. {
  31813. function callbackWrapper(response)
  31814. {
  31815. callback(response.content, response.encoding);
  31816. }
  31817. extensionServer.sendRequest({ command: commands.GetRequestContent, id: this._id }, callback && callbackWrapper);
  31818. }
  31819. }
  31820.  
  31821.  
  31822. function Panels()
  31823. {
  31824. var panels = {
  31825. elements: new ElementsPanel()
  31826. };
  31827.  
  31828. function panelGetter(name)
  31829. {
  31830. return panels[name];
  31831. }
  31832. for (var panel in panels)
  31833. this.__defineGetter__(panel, panelGetter.bind(null, panel));
  31834. }
  31835.  
  31836. Panels.prototype = {
  31837. create: function(title, icon, page, callback)
  31838. {
  31839. var id = "extension-panel-" + extensionServer.nextObjectId();
  31840. var request = {
  31841. command: commands.CreatePanel,
  31842. id: id,
  31843. title: title,
  31844. icon: icon,
  31845. page: page
  31846. };
  31847. extensionServer.sendRequest(request, callback && callback.bind(this, new ExtensionPanel(id)));
  31848. },
  31849.  
  31850. setOpenResourceHandler: function(callback)
  31851. {
  31852. var hadHandler = extensionServer.hasHandler(events.OpenResource);
  31853.  
  31854. if (!callback)
  31855. extensionServer.unregisterHandler(events.OpenResource);
  31856. else {
  31857. function callbackWrapper(message)
  31858. {
  31859.  
  31860. userAction = true;
  31861. try {
  31862. callback.call(null, new Resource(message.resource), message.lineNumber);
  31863. } finally {
  31864. userAction = false;
  31865. }
  31866. }
  31867. extensionServer.registerHandler(events.OpenResource, callbackWrapper);
  31868. }
  31869.  
  31870. if (hadHandler === !callback)
  31871. extensionServer.sendRequest({ command: commands.SetOpenResourceHandler, "handlerPresent": !!callback });
  31872. },
  31873.  
  31874. get SearchAction()
  31875. {
  31876. return apiPrivate.panels.SearchAction;
  31877. }
  31878. }
  31879.  
  31880.  
  31881. function ExtensionViewImpl(id)
  31882. {
  31883. this._id = id;
  31884.  
  31885. function dispatchShowEvent(message)
  31886. {
  31887. var frameIndex = message.arguments[0];
  31888. this._fire(window.parent.frames[frameIndex]);
  31889. }
  31890. this.onShown = new EventSink(events.ViewShown + id, dispatchShowEvent);
  31891. this.onHidden = new EventSink(events.ViewHidden + id);
  31892. }
  31893.  
  31894.  
  31895. function PanelWithSidebarImpl(id)
  31896. {
  31897. this._id = id;
  31898. }
  31899.  
  31900. PanelWithSidebarImpl.prototype = {
  31901. createSidebarPane: function(title, callback)
  31902. {
  31903. var id = "extension-sidebar-" + extensionServer.nextObjectId();
  31904. var request = {
  31905. command: commands.CreateSidebarPane,
  31906. panel: this._id,
  31907. id: id,
  31908. title: title
  31909. };
  31910. function callbackWrapper()
  31911. {
  31912. callback(new ExtensionSidebarPane(id));
  31913. }
  31914. extensionServer.sendRequest(request, callback && callbackWrapper);
  31915. },
  31916.  
  31917. __proto__: ExtensionViewImpl.prototype
  31918. }
  31919.  
  31920.  
  31921. function ElementsPanel()
  31922. {
  31923. var id = "elements";
  31924. PanelWithSidebar.call(this, id);
  31925. this.onSelectionChanged = new EventSink(events.ElementsPanelObjectSelected);
  31926. }
  31927.  
  31928.  
  31929. function ExtensionPanelImpl(id)
  31930. {
  31931. ExtensionViewImpl.call(this, id);
  31932. this.onSearch = new EventSink(events.PanelSearch + id);
  31933. }
  31934.  
  31935. ExtensionPanelImpl.prototype = {
  31936. createStatusBarButton: function(iconPath, tooltipText, disabled)
  31937. {
  31938. var id = "button-" + extensionServer.nextObjectId();
  31939. var request = {
  31940. command: commands.CreateStatusBarButton,
  31941. panel: this._id,
  31942. id: id,
  31943. icon: iconPath,
  31944. tooltip: tooltipText,
  31945. disabled: !!disabled
  31946. };
  31947. extensionServer.sendRequest(request);
  31948. return new Button(id);
  31949. },
  31950.  
  31951. show: function()
  31952. {
  31953. if (!userAction)
  31954. return;
  31955.  
  31956. var request = {
  31957. command: commands.ShowPanel,
  31958. id: this._id
  31959. };
  31960. extensionServer.sendRequest(request);
  31961. },
  31962.  
  31963. __proto__: ExtensionViewImpl.prototype
  31964. }
  31965.  
  31966.  
  31967. function ExtensionSidebarPaneImpl(id)
  31968. {
  31969. ExtensionViewImpl.call(this, id);
  31970. }
  31971.  
  31972. ExtensionSidebarPaneImpl.prototype = {
  31973. setHeight: function(height)
  31974. {
  31975. extensionServer.sendRequest({ command: commands.SetSidebarHeight, id: this._id, height: height });
  31976. },
  31977.  
  31978. setExpression: function(expression, rootTitle, evaluateOptions)
  31979. {
  31980. var callback = extractCallbackArgument(arguments);
  31981. var request = {
  31982. command: commands.SetSidebarContent,
  31983. id: this._id,
  31984. expression: expression,
  31985. rootTitle: rootTitle,
  31986. evaluateOnPage: true,
  31987. };
  31988. if (typeof evaluateOptions === "object")
  31989. request.evaluateOptions = evaluateOptions;
  31990. extensionServer.sendRequest(request, callback);
  31991. },
  31992.  
  31993. setObject: function(jsonObject, rootTitle, callback)
  31994. {
  31995. extensionServer.sendRequest({ command: commands.SetSidebarContent, id: this._id, expression: jsonObject, rootTitle: rootTitle }, callback);
  31996. },
  31997.  
  31998. setPage: function(page)
  31999. {
  32000. extensionServer.sendRequest({ command: commands.SetSidebarPage, id: this._id, page: page });
  32001. }
  32002. }
  32003.  
  32004.  
  32005. function ButtonImpl(id)
  32006. {
  32007. this._id = id;
  32008. this.onClicked = new EventSink(events.ButtonClicked + id);
  32009. }
  32010.  
  32011. ButtonImpl.prototype = {
  32012. update: function(iconPath, tooltipText, disabled)
  32013. {
  32014. var request = {
  32015. command: commands.UpdateButton,
  32016. id: this._id,
  32017. icon: iconPath,
  32018. tooltip: tooltipText,
  32019. disabled: !!disabled
  32020. };
  32021. extensionServer.sendRequest(request);
  32022. }
  32023. };
  32024.  
  32025.  
  32026. function Audits()
  32027. {
  32028. }
  32029.  
  32030. Audits.prototype = {
  32031. addCategory: function(displayName, resultCount)
  32032. {
  32033. var id = "extension-audit-category-" + extensionServer.nextObjectId();
  32034. if (typeof resultCount !== "undefined")
  32035. console.warn("Passing resultCount to audits.addCategory() is deprecated. Use AuditResult.updateProgress() instead.");
  32036. extensionServer.sendRequest({ command: commands.AddAuditCategory, id: id, displayName: displayName, resultCount: resultCount });
  32037. return new AuditCategory(id);
  32038. }
  32039. }
  32040.  
  32041.  
  32042. function AuditCategoryImpl(id)
  32043. {
  32044. function dispatchAuditEvent(request)
  32045. {
  32046. var auditResult = new AuditResult(request.arguments[0]);
  32047. try {
  32048. this._fire(auditResult);
  32049. } catch (e) {
  32050. console.error("Uncaught exception in extension audit event handler: " + e);
  32051. auditResult.done();
  32052. }
  32053. }
  32054. this._id = id;
  32055. this.onAuditStarted = new EventSink(events.AuditStarted + id, dispatchAuditEvent);
  32056. }
  32057.  
  32058.  
  32059. function AuditResultImpl(id)
  32060. {
  32061. this._id = id;
  32062.  
  32063. this.createURL = this._nodeFactory.bind(null, "url");
  32064. this.createSnippet = this._nodeFactory.bind(null, "snippet");
  32065. this.createText = this._nodeFactory.bind(null, "text");
  32066. this.createObject = this._nodeFactory.bind(null, "object");
  32067. this.createNode = this._nodeFactory.bind(null, "node");
  32068. }
  32069.  
  32070. AuditResultImpl.prototype = {
  32071. addResult: function(displayName, description, severity, details)
  32072. {
  32073.  
  32074. if (details && !(details instanceof AuditResultNode))
  32075. details = new AuditResultNode(details instanceof Array ? details : [details]);
  32076.  
  32077. var request = {
  32078. command: commands.AddAuditResult,
  32079. resultId: this._id,
  32080. displayName: displayName,
  32081. description: description,
  32082. severity: severity,
  32083. details: details
  32084. };
  32085. extensionServer.sendRequest(request);
  32086. },
  32087.  
  32088. createResult: function()
  32089. {
  32090. return new AuditResultNode(Array.prototype.slice.call(arguments));
  32091. },
  32092.  
  32093. updateProgress: function(worked, totalWork)
  32094. {
  32095. extensionServer.sendRequest({ command: commands.UpdateAuditProgress, resultId: this._id, progress: worked / totalWork });
  32096. },
  32097.  
  32098. done: function()
  32099. {
  32100. extensionServer.sendRequest({ command: commands.StopAuditCategoryRun, resultId: this._id });
  32101. },
  32102.  
  32103. get Severity()
  32104. {
  32105. return apiPrivate.audits.Severity;
  32106. },
  32107.  
  32108. createResourceLink: function(url, lineNumber)
  32109. {
  32110. return {
  32111. type: "resourceLink",
  32112. arguments: [url, lineNumber && lineNumber - 1]
  32113. };
  32114. },
  32115.  
  32116. _nodeFactory: function(type)
  32117. {
  32118. return {
  32119. type: type,
  32120. arguments: Array.prototype.slice.call(arguments, 1)
  32121. };
  32122. }
  32123. }
  32124.  
  32125.  
  32126. function AuditResultNode(contents)
  32127. {
  32128. this.contents = contents;
  32129. this.children = [];
  32130. this.expanded = false;
  32131. }
  32132.  
  32133. AuditResultNode.prototype = {
  32134. addChild: function()
  32135. {
  32136. var node = new AuditResultNode(Array.prototype.slice.call(arguments));
  32137. this.children.push(node);
  32138. return node;
  32139. }
  32140. };
  32141.  
  32142.  
  32143. function InspectedWindow()
  32144. {
  32145. function dispatchResourceEvent(message)
  32146. {
  32147. this._fire(new Resource(message.arguments[0]));
  32148. }
  32149. function dispatchResourceContentEvent(message)
  32150. {
  32151. this._fire(new Resource(message.arguments[0]), message.arguments[1]);
  32152. }
  32153. this.onResourceAdded = new EventSink(events.ResourceAdded, dispatchResourceEvent);
  32154. this.onResourceContentCommitted = new EventSink(events.ResourceContentCommitted, dispatchResourceContentEvent);
  32155. }
  32156.  
  32157. InspectedWindow.prototype = {
  32158. reload: function(optionsOrUserAgent)
  32159. {
  32160. var options = null;
  32161. if (typeof optionsOrUserAgent === "object")
  32162. options = optionsOrUserAgent;
  32163. else if (typeof optionsOrUserAgent === "string") {
  32164. options = { userAgent: optionsOrUserAgent };
  32165. console.warn("Passing userAgent as string parameter to inspectedWindow.reload() is deprecated. " +
  32166. "Use inspectedWindow.reload({ userAgent: value}) instead.");
  32167. }
  32168. return extensionServer.sendRequest({ command: commands.Reload, options: options });
  32169. },
  32170.  
  32171. eval: function(expression, evaluateOptions)
  32172. {
  32173. var callback = extractCallbackArgument(arguments);
  32174. function callbackWrapper(result)
  32175. {
  32176. callback(result.value, result.isException);
  32177. }
  32178. var request = {
  32179. command: commands.EvaluateOnInspectedPage,
  32180. expression: expression
  32181. };
  32182. if (typeof evaluateOptions === "object")
  32183. request.evaluateOptions = evaluateOptions;
  32184. return extensionServer.sendRequest(request, callback && callbackWrapper);
  32185. },
  32186.  
  32187. getResources: function(callback)
  32188. {
  32189. function wrapResource(resourceData)
  32190. {
  32191. return new Resource(resourceData);
  32192. }
  32193. function callbackWrapper(resources)
  32194. {
  32195. callback(resources.map(wrapResource));
  32196. }
  32197. return extensionServer.sendRequest({ command: commands.GetPageResources }, callback && callbackWrapper);
  32198. }
  32199. }
  32200.  
  32201.  
  32202. function ResourceImpl(resourceData)
  32203. {
  32204. this._url = resourceData.url
  32205. this._type = resourceData.type;
  32206. }
  32207.  
  32208. ResourceImpl.prototype = {
  32209. get url()
  32210. {
  32211. return this._url;
  32212. },
  32213.  
  32214. get type()
  32215. {
  32216. return this._type;
  32217. },
  32218.  
  32219. getContent: function(callback)
  32220. {
  32221. function callbackWrapper(response)
  32222. {
  32223. callback(response.content, response.encoding);
  32224. }
  32225.  
  32226. return extensionServer.sendRequest({ command: commands.GetResourceContent, url: this._url }, callback && callbackWrapper);
  32227. },
  32228.  
  32229. setContent: function(content, commit, callback)
  32230. {
  32231. return extensionServer.sendRequest({ command: commands.SetResourceContent, url: this._url, content: content, commit: commit }, callback);
  32232. }
  32233. }
  32234.  
  32235.  
  32236. function TimelineImpl()
  32237. {
  32238. this.onEventRecorded = new EventSink(events.TimelineEventRecorded);
  32239. }
  32240.  
  32241.  
  32242. function ExtensionServerClient()
  32243. {
  32244. this._callbacks = {};
  32245. this._handlers = {};
  32246. this._lastRequestId = 0;
  32247. this._lastObjectId = 0;
  32248.  
  32249. this.registerHandler("callback", this._onCallback.bind(this));
  32250.  
  32251. var channel = new MessageChannel();
  32252. this._port = channel.port1;
  32253. this._port.addEventListener("message", this._onMessage.bind(this), false);
  32254. this._port.start();
  32255.  
  32256. window.parent.postMessage("registerExtension", [ channel.port2 ], "*");
  32257. }
  32258.  
  32259. ExtensionServerClient.prototype = {
  32260.  
  32261. sendRequest: function(message, callback)
  32262. {
  32263. if (typeof callback === "function")
  32264. message.requestId = this._registerCallback(callback);
  32265. return this._port.postMessage(message);
  32266. },
  32267.  
  32268. hasHandler: function(command)
  32269. {
  32270. return !!this._handlers[command];
  32271. },
  32272.  
  32273. registerHandler: function(command, handler)
  32274. {
  32275. this._handlers[command] = handler;
  32276. },
  32277.  
  32278. unregisterHandler: function(command)
  32279. {
  32280. delete this._handlers[command];
  32281. },
  32282.  
  32283. nextObjectId: function()
  32284. {
  32285. return injectedScriptId + "_" + ++this._lastObjectId;
  32286. },
  32287.  
  32288. _registerCallback: function(callback)
  32289. {
  32290. var id = ++this._lastRequestId;
  32291. this._callbacks[id] = callback;
  32292. return id;
  32293. },
  32294.  
  32295. _onCallback: function(request)
  32296. {
  32297. if (request.requestId in this._callbacks) {
  32298. var callback = this._callbacks[request.requestId];
  32299. delete this._callbacks[request.requestId];
  32300. callback(request.result);
  32301. }
  32302. },
  32303.  
  32304. _onMessage: function(event)
  32305. {
  32306. var request = event.data;
  32307. var handler = this._handlers[request.command];
  32308. if (handler)
  32309. handler.call(this, request);
  32310. }
  32311. }
  32312.  
  32313. function populateInterfaceClass(interface, implementation)
  32314. {
  32315. for (var member in implementation) {
  32316. if (member.charAt(0) === "_")
  32317. continue;
  32318. var descriptor = null;
  32319.  
  32320. for (var owner = implementation; owner && !descriptor; owner = owner.__proto__)
  32321. descriptor = Object.getOwnPropertyDescriptor(owner, member);
  32322. if (!descriptor)
  32323. continue;
  32324. if (typeof descriptor.value === "function")
  32325. interface[member] = descriptor.value.bind(implementation);
  32326. else if (typeof descriptor.get === "function")
  32327. interface.__defineGetter__(member, descriptor.get.bind(implementation));
  32328. else
  32329. Object.defineProperty(interface, member, descriptor);
  32330. }
  32331. }
  32332.  
  32333. function declareInterfaceClass(implConstructor)
  32334. {
  32335. return function()
  32336. {
  32337. var impl = { __proto__: implConstructor.prototype };
  32338. implConstructor.apply(impl, arguments);
  32339. populateInterfaceClass(this, impl);
  32340. }
  32341. }
  32342.  
  32343. function defineDeprecatedProperty(object, className, oldName, newName)
  32344. {
  32345. var warningGiven = false;
  32346. function getter()
  32347. {
  32348. if (!warningGiven) {
  32349. console.warn(className + "." + oldName + " is deprecated. Use " + className + "." + newName + " instead");
  32350. warningGiven = true;
  32351. }
  32352. return object[newName];
  32353. }
  32354. object.__defineGetter__(oldName, getter);
  32355. }
  32356.  
  32357. function extractCallbackArgument(args)
  32358. {
  32359. var lastArgument = args[args.length - 1];
  32360. return typeof lastArgument === "function" ? lastArgument : undefined;
  32361. }
  32362.  
  32363. var AuditCategory = declareInterfaceClass(AuditCategoryImpl);
  32364. var AuditResult = declareInterfaceClass(AuditResultImpl);
  32365. var Button = declareInterfaceClass(ButtonImpl);
  32366. var EventSink = declareInterfaceClass(EventSinkImpl);
  32367. var ExtensionPanel = declareInterfaceClass(ExtensionPanelImpl);
  32368. var ExtensionSidebarPane = declareInterfaceClass(ExtensionSidebarPaneImpl);
  32369. var PanelWithSidebar = declareInterfaceClass(PanelWithSidebarImpl);
  32370. var Request = declareInterfaceClass(RequestImpl);
  32371. var Resource = declareInterfaceClass(ResourceImpl);
  32372. var Timeline = declareInterfaceClass(TimelineImpl);
  32373.  
  32374. var extensionServer = new ExtensionServerClient();
  32375.  
  32376. return new InspectorExtensionAPI();
  32377. }
  32378.  
  32379.  
  32380. function buildPlatformExtensionAPI(extensionInfo)
  32381. {
  32382. function platformExtensionAPI(coreAPI)
  32383. {
  32384. window.webInspector = coreAPI;
  32385. }
  32386. return platformExtensionAPI.toString();
  32387. }
  32388.  
  32389.  
  32390. function buildExtensionAPIInjectedScript(extensionInfo)
  32391. {
  32392. return "(function(injectedScriptHost, inspectedWindow, injectedScriptId){ " +
  32393. defineCommonExtensionSymbols.toString() + ";" +
  32394. injectedExtensionAPI.toString() + ";" +
  32395. buildPlatformExtensionAPI(extensionInfo) + ";" +
  32396. "platformExtensionAPI(injectedExtensionAPI(injectedScriptId));" +
  32397. "return {};" +
  32398. "})";
  32399. }
  32400.  
  32401.  
  32402.  
  32403.  
  32404.  
  32405.  
  32406. WebInspector.ExtensionAuditCategory = function(extensionOrigin, id, displayName, ruleCount)
  32407. {
  32408. this._extensionOrigin = extensionOrigin;
  32409. this._id = id;
  32410. this._displayName = displayName;
  32411. this._ruleCount  = ruleCount;
  32412. }
  32413.  
  32414. WebInspector.ExtensionAuditCategory.prototype = {
  32415.  
  32416. get id()
  32417. {
  32418. return this._id;
  32419. },
  32420.  
  32421. get displayName()
  32422. {
  32423. return this._displayName;
  32424. },
  32425.  
  32426.  
  32427. run: function(requests, ruleResultCallback, categoryDoneCallback, progress)
  32428. {
  32429. var results = new WebInspector.ExtensionAuditCategoryResults(this, ruleResultCallback, categoryDoneCallback, progress);
  32430. WebInspector.extensionServer.startAuditRun(this, results);
  32431. }
  32432. }
  32433.  
  32434.  
  32435. WebInspector.ExtensionAuditCategoryResults = function(category, ruleResultCallback, categoryDoneCallback, progress)
  32436. {
  32437. this._category = category;
  32438. this._ruleResultCallback = ruleResultCallback;
  32439. this._categoryDoneCallback = categoryDoneCallback;
  32440. this._progress = progress;
  32441. this._progress.setTotalWork(1);
  32442. this._expectedResults = category._ruleCount;
  32443. this._actualResults = 0;
  32444.  
  32445. this.id = category.id + "-" + ++WebInspector.ExtensionAuditCategoryResults._lastId;
  32446. }
  32447.  
  32448. WebInspector.ExtensionAuditCategoryResults.prototype = {
  32449. done: function()
  32450. {
  32451. WebInspector.extensionServer.stopAuditRun(this);
  32452. this._progress.done();
  32453. this._categoryDoneCallback();
  32454. },
  32455.  
  32456. addResult: function(displayName, description, severity, details)
  32457. {
  32458. var result = new WebInspector.AuditRuleResult(displayName);
  32459. result.addChild(description);
  32460. result.severity = severity;
  32461. if (details)
  32462. this._addNode(result, details);
  32463. this._addResult(result);
  32464. },
  32465.  
  32466. _addNode: function(parent, node)
  32467. {
  32468. var contents = WebInspector.auditFormatters.partiallyApply(WebInspector.ExtensionAuditFormatters, this, node.contents);
  32469. var addedNode = parent.addChild(contents, node.expanded);
  32470. if (node.children) {
  32471. for (var i = 0; i < node.children.length; ++i)
  32472. this._addNode(addedNode, node.children[i]);
  32473. }
  32474. },
  32475.  
  32476. _addResult: function(result)
  32477. {
  32478. this._ruleResultCallback(result);
  32479. ++this._actualResults;
  32480. if (typeof this._expectedResults === "number") {
  32481. this._progress.setWorked(this._actualResults / this._expectedResults);
  32482. if (this._actualResults === this._expectedResults)
  32483. this.done();
  32484. }
  32485. },
  32486.  
  32487.  
  32488. updateProgress: function(progress)
  32489. {
  32490. this._progress.setWorked(progress);
  32491. },
  32492.  
  32493.  
  32494. evaluate: function(expression, evaluateOptions, callback)
  32495. {
  32496.  
  32497. function onEvaluate(error, result, wasThrown)
  32498. {
  32499. if (wasThrown)
  32500. return;
  32501. var object = WebInspector.RemoteObject.fromPayload(result);
  32502. callback(object);
  32503. }
  32504. WebInspector.extensionServer.evaluate(expression, false, false, evaluateOptions, this._category._extensionOrigin, onEvaluate);
  32505. }
  32506. }
  32507.  
  32508. WebInspector.ExtensionAuditFormatters = {
  32509.  
  32510. object: function(expression, title, evaluateOptions)
  32511. {
  32512. var parentElement = document.createElement("div");
  32513. function onEvaluate(remoteObject)
  32514. {
  32515. var section = new WebInspector.ObjectPropertiesSection(remoteObject, title);
  32516. section.expanded = true;
  32517. section.editable = false;
  32518. parentElement.appendChild(section.element);
  32519. }
  32520. this.evaluate(expression, evaluateOptions, onEvaluate);
  32521. return parentElement;
  32522. },
  32523.  
  32524.  
  32525. node: function(expression, evaluateOptions)
  32526. {
  32527. var parentElement = document.createElement("div");
  32528.  
  32529. function onNodeAvailable(nodeId)
  32530. {
  32531. if (!nodeId)
  32532. return;
  32533. var treeOutline = new WebInspector.ElementsTreeOutline(false, false, true);
  32534. treeOutline.rootDOMNode = WebInspector.domAgent.nodeForId(nodeId);
  32535. treeOutline.element.addStyleClass("outline-disclosure");
  32536. treeOutline.setVisible(true);
  32537. parentElement.appendChild(treeOutline.element);
  32538. }
  32539.  
  32540. function onEvaluate(remoteObject)
  32541. {
  32542. remoteObject.pushNodeToFrontend(onNodeAvailable);
  32543. }
  32544. this.evaluate(expression, evaluateOptions, onEvaluate);
  32545. return parentElement;
  32546. }
  32547. }
  32548.  
  32549. WebInspector.ExtensionAuditCategoryResults._lastId = 0;
  32550.  
  32551.  
  32552.  
  32553.  
  32554.  
  32555.  
  32556. WebInspector.ExtensionServer = function()
  32557. {
  32558. this._clientObjects = {};
  32559. this._handlers = {};
  32560. this._subscribers = {};
  32561. this._subscriptionStartHandlers = {};
  32562. this._subscriptionStopHandlers = {};
  32563. this._extraHeaders = {};
  32564. this._requests = {};
  32565. this._lastRequestId = 0;
  32566. this._registeredExtensions = {};
  32567. this._status = new WebInspector.ExtensionStatus();
  32568.  
  32569. var commands = WebInspector.extensionAPI.Commands;
  32570.  
  32571. this._registerHandler(commands.AddAuditCategory, this._onAddAuditCategory.bind(this));
  32572. this._registerHandler(commands.AddAuditResult, this._onAddAuditResult.bind(this));
  32573. this._registerHandler(commands.AddConsoleMessage, this._onAddConsoleMessage.bind(this));
  32574. this._registerHandler(commands.AddRequestHeaders, this._onAddRequestHeaders.bind(this));
  32575. this._registerHandler(commands.CreatePanel, this._onCreatePanel.bind(this));
  32576. this._registerHandler(commands.CreateSidebarPane, this._onCreateSidebarPane.bind(this));
  32577. this._registerHandler(commands.CreateStatusBarButton, this._onCreateStatusBarButton.bind(this));
  32578. this._registerHandler(commands.EvaluateOnInspectedPage, this._onEvaluateOnInspectedPage.bind(this));
  32579. this._registerHandler(commands.GetHAR, this._onGetHAR.bind(this));
  32580. this._registerHandler(commands.GetConsoleMessages, this._onGetConsoleMessages.bind(this));
  32581. this._registerHandler(commands.GetPageResources, this._onGetPageResources.bind(this));
  32582. this._registerHandler(commands.GetRequestContent, this._onGetRequestContent.bind(this));
  32583. this._registerHandler(commands.GetResourceContent, this._onGetResourceContent.bind(this));
  32584. this._registerHandler(commands.Log, this._onLog.bind(this));
  32585. this._registerHandler(commands.Reload, this._onReload.bind(this));
  32586. this._registerHandler(commands.SetOpenResourceHandler, this._onSetOpenResourceHandler.bind(this));
  32587. this._registerHandler(commands.SetResourceContent, this._onSetResourceContent.bind(this));
  32588. this._registerHandler(commands.SetSidebarHeight, this._onSetSidebarHeight.bind(this));
  32589. this._registerHandler(commands.SetSidebarContent, this._onSetSidebarContent.bind(this));
  32590. this._registerHandler(commands.SetSidebarPage, this._onSetSidebarPage.bind(this));
  32591. this._registerHandler(commands.ShowPanel, this._onShowPanel.bind(this));
  32592. this._registerHandler(commands.StopAuditCategoryRun, this._onStopAuditCategoryRun.bind(this));
  32593. this._registerHandler(commands.Subscribe, this._onSubscribe.bind(this));
  32594. this._registerHandler(commands.Unsubscribe, this._onUnsubscribe.bind(this));
  32595. this._registerHandler(commands.UpdateButton, this._onUpdateButton.bind(this));
  32596. this._registerHandler(commands.UpdateAuditProgress, this._onUpdateAuditProgress.bind(this));
  32597.  
  32598. window.addEventListener("message", this._onWindowMessage.bind(this), false);
  32599. }
  32600.  
  32601. WebInspector.ExtensionServer.prototype = {
  32602. hasExtensions: function()
  32603. {
  32604. return !!Object.keys(this._registeredExtensions).length;
  32605. },
  32606.  
  32607. notifySearchAction: function(panelId, action, searchString)
  32608. {
  32609. this._postNotification(WebInspector.extensionAPI.Events.PanelSearch + panelId, action, searchString);
  32610. },
  32611.  
  32612. notifyViewShown: function(identifier, frameIndex)
  32613. {
  32614. this._postNotification(WebInspector.extensionAPI.Events.ViewShown + identifier, frameIndex);
  32615. },
  32616.  
  32617. notifyViewHidden: function(identifier)
  32618. {
  32619. this._postNotification(WebInspector.extensionAPI.Events.ViewHidden + identifier);
  32620. },
  32621.  
  32622. notifyButtonClicked: function(identifier)
  32623. {
  32624. this._postNotification(WebInspector.extensionAPI.Events.ButtonClicked + identifier);
  32625. },
  32626.  
  32627. _inspectedURLChanged: function(event)
  32628. {
  32629. this._requests = {};
  32630. var url = event.data;
  32631. this._postNotification(WebInspector.extensionAPI.Events.InspectedURLChanged, url);
  32632. },
  32633.  
  32634. _mainFrameNavigated: function(event)
  32635. {
  32636. this._postNotification(WebInspector.extensionAPI.Events.Reset);
  32637. },
  32638.  
  32639. startAuditRun: function(category, auditRun)
  32640. {
  32641. this._clientObjects[auditRun.id] = auditRun;
  32642. this._postNotification("audit-started-" + category.id, auditRun.id);
  32643. },
  32644.  
  32645. stopAuditRun: function(auditRun)
  32646. {
  32647. delete this._clientObjects[auditRun.id];
  32648. },
  32649.  
  32650.  
  32651. _postNotification: function(type, vararg)
  32652. {
  32653. var subscribers = this._subscribers[type];
  32654. if (!subscribers)
  32655. return;
  32656. var message = {
  32657. command: "notify-" + type,
  32658. arguments: Array.prototype.slice.call(arguments, 1)
  32659. };
  32660. for (var i = 0; i < subscribers.length; ++i)
  32661. subscribers[i].postMessage(message);
  32662. },
  32663.  
  32664. _onSubscribe: function(message, port)
  32665. {
  32666. var subscribers = this._subscribers[message.type];
  32667. if (subscribers)
  32668. subscribers.push(port);
  32669. else {
  32670. this._subscribers[message.type] = [ port ];
  32671. if (this._subscriptionStartHandlers[message.type])
  32672. this._subscriptionStartHandlers[message.type]();
  32673. }
  32674. },
  32675.  
  32676. _onUnsubscribe: function(message, port)
  32677. {
  32678. var subscribers = this._subscribers[message.type];
  32679. if (!subscribers)
  32680. return;
  32681. subscribers.remove(port);
  32682. if (!subscribers.length) {
  32683. delete this._subscribers[message.type];
  32684. if (this._subscriptionStopHandlers[message.type])
  32685. this._subscriptionStopHandlers[message.type]();
  32686. }
  32687. },
  32688.  
  32689. _onAddRequestHeaders: function(message)
  32690. {
  32691. var id = message.extensionId;
  32692. if (typeof id !== "string")
  32693. return this._status.E_BADARGTYPE("extensionId", typeof id, "string");
  32694. var extensionHeaders = this._extraHeaders[id];
  32695. if (!extensionHeaders) {
  32696. extensionHeaders = {};
  32697. this._extraHeaders[id] = extensionHeaders;
  32698. }
  32699. for (var name in message.headers)
  32700. extensionHeaders[name] = message.headers[name];
  32701. var allHeaders =   ({});
  32702. for (var extension in this._extraHeaders) {
  32703. var headers = this._extraHeaders[extension];
  32704. for (name in headers) {
  32705. if (typeof headers[name] === "string")
  32706. allHeaders[name] = headers[name];
  32707. }
  32708. }
  32709. NetworkAgent.setExtraHTTPHeaders(allHeaders);
  32710. },
  32711.  
  32712. _onCreatePanel: function(message, port)
  32713. {
  32714. var id = message.id;
  32715.  
  32716.  
  32717. if (id in this._clientObjects || id in WebInspector.panels)
  32718. return this._status.E_EXISTS(id);
  32719.  
  32720. var page = this._expandResourcePath(port._extensionOrigin, message.page);
  32721. var panelDescriptor = new WebInspector.PanelDescriptor(id, message.title, undefined, undefined, new WebInspector.ExtensionPanel(id, page));
  32722. panelDescriptor.setIconURL(this._expandResourcePath(port._extensionOrigin, message.icon));
  32723. this._clientObjects[id] = panelDescriptor.panel();
  32724. WebInspector.inspectorView.addPanel(panelDescriptor);
  32725. return this._status.OK();
  32726. },
  32727.  
  32728. _onShowPanel: function(message)
  32729. {
  32730.  
  32731. WebInspector.showPanel(message.id);
  32732. },
  32733.  
  32734. _onCreateStatusBarButton: function(message, port)
  32735. {
  32736. var panel = this._clientObjects[message.panel];
  32737. if (!panel || !(panel instanceof WebInspector.ExtensionPanel))
  32738. return this._status.E_NOTFOUND(message.panel);
  32739. var button = new WebInspector.ExtensionButton(message.id, this._expandResourcePath(port._extensionOrigin, message.icon), message.tooltip, message.disabled);
  32740. this._clientObjects[message.id] = button;
  32741. panel.addStatusBarItem(button.element);
  32742. return this._status.OK();
  32743. },
  32744.  
  32745. _onUpdateButton: function(message, port)
  32746. {
  32747. var button = this._clientObjects[message.id];
  32748. if (!button || !(button instanceof WebInspector.ExtensionButton))
  32749. return this._status.E_NOTFOUND(message.id);
  32750. button.update(this._expandResourcePath(port._extensionOrigin, message.icon), message.tooltip, message.disabled);
  32751. return this._status.OK();
  32752. },
  32753.  
  32754. _onCreateSidebarPane: function(message)
  32755. {
  32756. var panel = WebInspector.panel(message.panel);
  32757. if (!panel)
  32758. return this._status.E_NOTFOUND(message.panel);
  32759. if (!panel.sidebarElement || !panel.sidebarPanes)
  32760. return this._status.E_NOTSUPPORTED();
  32761. var id = message.id;
  32762. var sidebar = new WebInspector.ExtensionSidebarPane(message.title, message.id);
  32763. this._clientObjects[id] = sidebar;
  32764. panel.sidebarPanes[id] = sidebar;
  32765. panel.sidebarElement.appendChild(sidebar.element);
  32766.  
  32767. return this._status.OK();
  32768. },
  32769.  
  32770. _onSetSidebarHeight: function(message)
  32771. {
  32772. var sidebar = this._clientObjects[message.id];
  32773. if (!sidebar)
  32774. return this._status.E_NOTFOUND(message.id);
  32775. sidebar.setHeight(message.height);
  32776. return this._status.OK();
  32777. },
  32778.  
  32779. _onSetSidebarContent: function(message, port)
  32780. {
  32781. var sidebar = this._clientObjects[message.id];
  32782. if (!sidebar)
  32783. return this._status.E_NOTFOUND(message.id);
  32784. function callback(error)
  32785. {
  32786. var result = error ? this._status.E_FAILED(error) : this._status.OK();
  32787. this._dispatchCallback(message.requestId, port, result);
  32788. }
  32789. if (message.evaluateOnPage)
  32790. return sidebar.setExpression(message.expression, message.rootTitle, message.evaluateOptions, port._extensionOrigin, callback.bind(this));
  32791. sidebar.setObject(message.expression, message.rootTitle, callback.bind(this));
  32792. },
  32793.  
  32794. _onSetSidebarPage: function(message, port)
  32795. {
  32796. var sidebar = this._clientObjects[message.id];
  32797. if (!sidebar)
  32798. return this._status.E_NOTFOUND(message.id);
  32799. sidebar.setPage(this._expandResourcePath(port._extensionOrigin, message.page));
  32800. },
  32801.  
  32802. _onSetOpenResourceHandler: function(message, port)
  32803. {
  32804. var name = this._registeredExtensions[port._extensionOrigin].name || ("Extension " + port._extensionOrigin);
  32805. if (message.handlerPresent)
  32806. WebInspector.openAnchorLocationRegistry.registerHandler(name, this._handleOpenURL.bind(this, port));
  32807. else
  32808. WebInspector.openAnchorLocationRegistry.unregisterHandler(name);
  32809. },
  32810.  
  32811. _handleOpenURL: function(port, details)
  32812. {
  32813. var url =   (details.url);
  32814. var contentProvider = WebInspector.workspace.uiSourceCodeForURL(url) || WebInspector.resourceForURL(url);
  32815. if (!contentProvider)
  32816. return false;
  32817.  
  32818. var lineNumber = details.lineNumber;
  32819. if (typeof lineNumber === "number")
  32820. lineNumber += 1;
  32821. port.postMessage({
  32822. command: "open-resource",
  32823. resource: this._makeResource(contentProvider),
  32824. lineNumber: lineNumber
  32825. });
  32826. return true;
  32827. },
  32828.  
  32829. _onLog: function(message)
  32830. {
  32831. WebInspector.log(message.message);
  32832. },
  32833.  
  32834. _onReload: function(message)
  32835. {
  32836. var options =   (message.options || {});
  32837. NetworkAgent.setUserAgentOverride(typeof options.userAgent === "string" ? options.userAgent : "");
  32838. var injectedScript;
  32839. if (options.injectedScript) {
  32840.  
  32841.  
  32842. injectedScript = "((function(){" + options.injectedScript + "})(),function(){return {}})";
  32843. }
  32844. PageAgent.reload(!!options.ignoreCache, injectedScript);
  32845. return this._status.OK();
  32846. },
  32847.  
  32848. _onEvaluateOnInspectedPage: function(message, port)
  32849. {
  32850.  
  32851. function callback(error, resultPayload, wasThrown)
  32852. {
  32853. var result = {};
  32854. if (error) {
  32855. result.isException = true;
  32856. result.value = error.toString();
  32857. }  else
  32858. result.value = resultPayload.value;
  32859.  
  32860. if (wasThrown)
  32861. result.isException = true;
  32862.  
  32863. this._dispatchCallback(message.requestId, port, result);
  32864. }
  32865. return this.evaluate(message.expression, true, true, message.evaluateOptions, port._extensionOrigin, callback.bind(this));
  32866. },
  32867.  
  32868. _onGetConsoleMessages: function()
  32869. {
  32870. return WebInspector.console.messages.map(this._makeConsoleMessage);
  32871. },
  32872.  
  32873. _onAddConsoleMessage: function(message)
  32874. {
  32875. function convertSeverity(level)
  32876. {
  32877. switch (level) {
  32878. case WebInspector.extensionAPI.console.Severity.Tip:
  32879. return WebInspector.ConsoleMessage.MessageLevel.Tip;
  32880. case WebInspector.extensionAPI.console.Severity.Log:
  32881. return WebInspector.ConsoleMessage.MessageLevel.Log;
  32882. case WebInspector.extensionAPI.console.Severity.Warning:
  32883. return WebInspector.ConsoleMessage.MessageLevel.Warning;
  32884. case WebInspector.extensionAPI.console.Severity.Error:
  32885. return WebInspector.ConsoleMessage.MessageLevel.Error;
  32886. case WebInspector.extensionAPI.console.Severity.Debug:
  32887. return WebInspector.ConsoleMessage.MessageLevel.Debug;
  32888. }
  32889. }
  32890. var level = convertSeverity(message.severity);
  32891. if (!level)
  32892. return this._status.E_BADARG("message.severity", message.severity);
  32893.  
  32894. var consoleMessage = WebInspector.ConsoleMessage.create(
  32895. WebInspector.ConsoleMessage.MessageSource.JS,
  32896. level,
  32897. message.text,
  32898. WebInspector.ConsoleMessage.MessageType.Log,
  32899. message.url,
  32900. message.line);
  32901. WebInspector.console.addMessage(consoleMessage);
  32902. },
  32903.  
  32904. _makeConsoleMessage: function(message)
  32905. {
  32906. function convertLevel(level)
  32907. {
  32908. if (!level)
  32909. return;
  32910. switch (level) {
  32911. case WebInspector.ConsoleMessage.MessageLevel.Tip:
  32912. return WebInspector.extensionAPI.console.Severity.Tip;
  32913. case WebInspector.ConsoleMessage.MessageLevel.Log:
  32914. return WebInspector.extensionAPI.console.Severity.Log;
  32915. case WebInspector.ConsoleMessage.MessageLevel.Warning:
  32916. return WebInspector.extensionAPI.console.Severity.Warning;
  32917. case WebInspector.ConsoleMessage.MessageLevel.Error:
  32918. return WebInspector.extensionAPI.console.Severity.Error;
  32919. case WebInspector.ConsoleMessage.MessageLevel.Debug:
  32920. return WebInspector.extensionAPI.console.Severity.Debug;
  32921. default:
  32922. return WebInspector.extensionAPI.console.Severity.Log;
  32923. }
  32924. }
  32925. var result = {
  32926. severity: convertLevel(message.level),
  32927. text: message.text,
  32928. };
  32929. if (message.url)
  32930. result.url = message.url;
  32931. if (message.line)
  32932. result.line = message.line;
  32933. return result;
  32934. },
  32935.  
  32936. _onGetHAR: function()
  32937. {
  32938. var requests = WebInspector.networkLog.requests;
  32939. var harLog = (new WebInspector.HARLog(requests)).build();
  32940. for (var i = 0; i < harLog.entries.length; ++i)
  32941. harLog.entries[i]._requestId = this._requestId(requests[i]);
  32942. return harLog;
  32943. },
  32944.  
  32945.  
  32946. _makeResource: function(contentProvider)
  32947. {
  32948. return {
  32949. url: contentProvider.contentURL(),
  32950. type: contentProvider.contentType().name()
  32951. };
  32952. },
  32953.  
  32954. _onGetPageResources: function()
  32955. {
  32956. var resources = {};
  32957.  
  32958. function pushResourceData(contentProvider)
  32959. {
  32960. if (!resources[contentProvider.contentURL()])
  32961. resources[contentProvider.contentURL()] = this._makeResource(contentProvider);
  32962. }
  32963. WebInspector.workspace.uiSourceCodes().forEach(pushResourceData.bind(this));
  32964. WebInspector.resourceTreeModel.forAllResources(pushResourceData.bind(this));
  32965. return Object.values(resources);
  32966. },
  32967.  
  32968.  
  32969. _getResourceContent: function(contentProvider, message, port)
  32970. {
  32971.  
  32972. function onContentAvailable(content, contentEncoded, mimeType)
  32973. {
  32974. var response = {
  32975. encoding: contentEncoded ? "base64" : "",
  32976. content: content
  32977. };
  32978. this._dispatchCallback(message.requestId, port, response);
  32979. }
  32980. contentProvider.requestContent(onContentAvailable.bind(this));
  32981. },
  32982.  
  32983. _onGetRequestContent: function(message, port)
  32984. {
  32985. var request = this._requestById(message.id);
  32986. if (!request)
  32987. return this._status.E_NOTFOUND(message.id);
  32988. this._getResourceContent(request, message, port);
  32989. },
  32990.  
  32991. _onGetResourceContent: function(message, port)
  32992. {
  32993. var url =   (message.url);
  32994. var contentProvider = WebInspector.workspace.uiSourceCodeForURL(url) || WebInspector.resourceForURL(url);
  32995. if (!contentProvider)
  32996. return this._status.E_NOTFOUND(url);
  32997. this._getResourceContent(contentProvider, message, port);
  32998. },
  32999.  
  33000. _onSetResourceContent: function(message, port)
  33001. {
  33002.  
  33003. function callbackWrapper(error)
  33004. {
  33005. var response = error ? this._status.E_FAILED(error) : this._status.OK();
  33006. this._dispatchCallback(message.requestId, port, response);
  33007. }
  33008.  
  33009. var url =   (message.url);
  33010. var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url);
  33011. if (!uiSourceCode) {
  33012. var resource = WebInspector.resourceTreeModel.resourceForURL(url);
  33013. if (!resource)
  33014. return this._status.E_NOTFOUND(url);
  33015. return this._status.E_NOTSUPPORTED("Resource is not editable")
  33016. }
  33017. uiSourceCode.setWorkingCopy(message.content);
  33018. if (message.commit)
  33019. uiSourceCode.commitWorkingCopy(callbackWrapper.bind(this));
  33020. else
  33021. callbackWrapper.call(this, null);
  33022. },
  33023.  
  33024. _requestId: function(request)
  33025. {
  33026. if (!request._extensionRequestId) {
  33027. request._extensionRequestId = ++this._lastRequestId;
  33028. this._requests[request._extensionRequestId] = request;
  33029. }
  33030. return request._extensionRequestId;
  33031. },
  33032.  
  33033. _requestById: function(id)
  33034. {
  33035. return this._requests[id];
  33036. },
  33037.  
  33038. _onAddAuditCategory: function(message, port)
  33039. {
  33040. var category = new WebInspector.ExtensionAuditCategory(port._extensionOrigin, message.id, message.displayName, message.resultCount);
  33041. if (WebInspector.panel("audits").getCategory(category.id))
  33042. return this._status.E_EXISTS(category.id);
  33043. this._clientObjects[message.id] = category;
  33044. WebInspector.panel("audits").addCategory(category);
  33045. },
  33046.  
  33047. _onAddAuditResult: function(message)
  33048. {
  33049. var auditResult = this._clientObjects[message.resultId];
  33050. if (!auditResult)
  33051. return this._status.E_NOTFOUND(message.resultId);
  33052. try {
  33053. auditResult.addResult(message.displayName, message.description, message.severity, message.details);
  33054. } catch (e) {
  33055. return e;
  33056. }
  33057. return this._status.OK();
  33058. },
  33059.  
  33060. _onUpdateAuditProgress: function(message)
  33061. {
  33062. var auditResult = this._clientObjects[message.resultId];
  33063. if (!auditResult)
  33064. return this._status.E_NOTFOUND(message.resultId);
  33065. auditResult.updateProgress(Math.min(Math.max(0, message.progress), 1));
  33066. },
  33067.  
  33068. _onStopAuditCategoryRun: function(message)
  33069. {
  33070. var auditRun = this._clientObjects[message.resultId];
  33071. if (!auditRun)
  33072. return this._status.E_NOTFOUND(message.resultId);
  33073. auditRun.done();
  33074. },
  33075.  
  33076. _dispatchCallback: function(requestId, port, result)
  33077. {
  33078. if (requestId)
  33079. port.postMessage({ command: "callback", requestId: requestId, result: result });
  33080. },
  33081.  
  33082. initExtensions: function()
  33083. {
  33084. this._registerAutosubscriptionHandler(WebInspector.extensionAPI.Events.ConsoleMessageAdded,
  33085. WebInspector.console, WebInspector.ConsoleModel.Events.MessageAdded, this._notifyConsoleMessageAdded);
  33086. this._registerAutosubscriptionHandler(WebInspector.extensionAPI.Events.NetworkRequestFinished,
  33087. WebInspector.networkManager, WebInspector.NetworkManager.EventTypes.RequestFinished, this._notifyRequestFinished);
  33088. this._registerAutosubscriptionHandler(WebInspector.extensionAPI.Events.ResourceAdded,
  33089. WebInspector.workspace,
  33090. WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded,
  33091. this._notifyResourceAdded);
  33092. this._registerAutosubscriptionHandler(WebInspector.extensionAPI.Events.ElementsPanelObjectSelected,
  33093. WebInspector.notifications,
  33094. WebInspector.ElementsTreeOutline.Events.SelectedNodeChanged,
  33095. this._notifyElementsSelectionChanged);
  33096. this._registerAutosubscriptionHandler(WebInspector.extensionAPI.Events.ResourceContentCommitted,
  33097. WebInspector.workspace,
  33098. WebInspector.Workspace.Events.UISourceCodeContentCommitted,
  33099. this._notifyUISourceCodeContentCommitted);
  33100.  
  33101. function onTimelineSubscriptionStarted()
  33102. {
  33103. WebInspector.timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded,
  33104. this._notifyTimelineEventRecorded, this);
  33105. WebInspector.timelineManager.start();
  33106. }
  33107. function onTimelineSubscriptionStopped()
  33108. {
  33109. WebInspector.timelineManager.stop();
  33110. WebInspector.timelineManager.removeEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded,
  33111. this._notifyTimelineEventRecorded, this);
  33112. }
  33113. this._registerSubscriptionHandler(WebInspector.extensionAPI.Events.TimelineEventRecorded,
  33114. onTimelineSubscriptionStarted.bind(this), onTimelineSubscriptionStopped.bind(this));
  33115.  
  33116. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.InspectedURLChanged,
  33117. this._inspectedURLChanged, this);
  33118. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, this._mainFrameNavigated, this);
  33119. this._initDone = true;
  33120. if (this._pendingExtensions) {
  33121. this._pendingExtensions.forEach(this._innerAddExtension, this);
  33122. delete this._pendingExtensions;
  33123. }
  33124. InspectorExtensionRegistry.getExtensionsAsync();
  33125. },
  33126.  
  33127. _notifyConsoleMessageAdded: function(event)
  33128. {
  33129. this._postNotification(WebInspector.extensionAPI.Events.ConsoleMessageAdded, this._makeConsoleMessage(event.data));
  33130. },
  33131.  
  33132. _notifyResourceAdded: function(event)
  33133. {
  33134. var uiSourceCode =   (event.data);
  33135. this._postNotification(WebInspector.extensionAPI.Events.ResourceAdded, this._makeResource(uiSourceCode));
  33136. },
  33137.  
  33138. _notifyUISourceCodeContentCommitted: function(event)
  33139. {
  33140. var uiSourceCode =   (event.data.uiSourceCode);
  33141. var content =   (event.data.content);
  33142. this._postNotification(WebInspector.extensionAPI.Events.ResourceContentCommitted, this._makeResource(uiSourceCode), content);
  33143. },
  33144.  
  33145. _notifyRequestFinished: function(event)
  33146. {
  33147. var request =   (event.data);
  33148. this._postNotification(WebInspector.extensionAPI.Events.NetworkRequestFinished, this._requestId(request), (new WebInspector.HAREntry(request)).build());
  33149. },
  33150.  
  33151. _notifyElementsSelectionChanged: function()
  33152. {
  33153. this._postNotification(WebInspector.extensionAPI.Events.ElementsPanelObjectSelected);
  33154. },
  33155.  
  33156. _notifyTimelineEventRecorded: function(event)
  33157. {
  33158. this._postNotification(WebInspector.extensionAPI.Events.TimelineEventRecorded, event.data);
  33159. },
  33160.  
  33161.  
  33162. _addExtensions: function(extensions)
  33163. {
  33164. extensions.forEach(this._addExtension, this);
  33165. },
  33166.  
  33167. _addExtension: function(extensionInfo)
  33168. {
  33169. if (this._initDone) {
  33170. this._innerAddExtension(extensionInfo);
  33171. return;
  33172. }
  33173. if (this._pendingExtensions)
  33174. this._pendingExtensions.push(extensionInfo);
  33175. else
  33176. this._pendingExtensions = [extensionInfo];
  33177. },
  33178.  
  33179. _innerAddExtension: function(extensionInfo)
  33180. {
  33181. const urlOriginRegExp = new RegExp("([^:]+:\/\/[^/]*)\/"); 
  33182. var startPage = extensionInfo.startPage;
  33183. var name = extensionInfo.name;
  33184.  
  33185. try {
  33186. var originMatch = urlOriginRegExp.exec(startPage);
  33187. if (!originMatch) {
  33188. console.error("Skipping extension with invalid URL: " + startPage);
  33189. return false;
  33190. }
  33191. var extensionOrigin = originMatch[1];
  33192. if (!this._registeredExtensions[extensionOrigin]) {
  33193.  
  33194. InspectorFrontendHost.setInjectedScriptForOrigin(extensionOrigin, buildExtensionAPIInjectedScript(extensionInfo));
  33195. this._registeredExtensions[extensionOrigin] = { name: name };
  33196. }
  33197. var iframe = document.createElement("iframe");
  33198. iframe.src = startPage;
  33199. iframe.style.display = "none";
  33200. document.body.appendChild(iframe);
  33201. } catch (e) {
  33202. console.error("Failed to initialize extension " + startPage + ":" + e);
  33203. return false;
  33204. }
  33205. return true;
  33206. },
  33207.  
  33208. _onWindowMessage: function(event)
  33209. {
  33210. if (event.data === "registerExtension")
  33211. this._registerExtension(event.origin, event.ports[0]);
  33212. },
  33213.  
  33214. _registerExtension: function(origin, port)
  33215. {
  33216. if (!this._registeredExtensions.hasOwnProperty(origin)) {
  33217. if (origin !== window.location.origin) 
  33218. console.error("Ignoring unauthorized client request from " + origin);
  33219. return;
  33220. }
  33221. port._extensionOrigin = origin;
  33222. port.addEventListener("message", this._onmessage.bind(this), false);
  33223. port.start();
  33224. },
  33225.  
  33226. _onmessage: function(event)
  33227. {
  33228. var message = event.data;
  33229. var result;
  33230.  
  33231. if (message.command in this._handlers)
  33232. result = this._handlers[message.command](message, event.target);
  33233. else
  33234. result = this._status.E_NOTSUPPORTED(message.command);
  33235.  
  33236. if (result && message.requestId)
  33237. this._dispatchCallback(message.requestId, event.target, result);
  33238. },
  33239.  
  33240. _registerHandler: function(command, callback)
  33241. {
  33242. this._handlers[command] = callback;
  33243. },
  33244.  
  33245. _registerSubscriptionHandler: function(eventTopic, onSubscribeFirst, onUnsubscribeLast)
  33246. {
  33247. this._subscriptionStartHandlers[eventTopic] =  onSubscribeFirst;
  33248. this._subscriptionStopHandlers[eventTopic] =  onUnsubscribeLast;
  33249. },
  33250.  
  33251. _registerAutosubscriptionHandler: function(eventTopic, eventTarget, frontendEventType, handler)
  33252. {
  33253. this._registerSubscriptionHandler(eventTopic,
  33254. eventTarget.addEventListener.bind(eventTarget, frontendEventType, handler, this),
  33255. eventTarget.removeEventListener.bind(eventTarget, frontendEventType, handler, this));
  33256. },
  33257.  
  33258. _expandResourcePath: function(extensionPath, resourcePath)
  33259. {
  33260. if (!resourcePath)
  33261. return;
  33262. return extensionPath + this._normalizePath(resourcePath);
  33263. },
  33264.  
  33265. _normalizePath: function(path)
  33266. {
  33267. var source = path.split("/");
  33268. var result = [];
  33269.  
  33270. for (var i = 0; i < source.length; ++i) {
  33271. if (source[i] === ".")
  33272. continue;
  33273.  
  33274. if (source[i] === "")
  33275. continue;
  33276. if (source[i] === "..")
  33277. result.pop();
  33278. else
  33279. result.push(source[i]);
  33280. }
  33281. return "/" + result.join("/");
  33282. },
  33283.  
  33284.  
  33285. evaluate: function(expression, exposeCommandLineAPI, returnByValue, options, securityOrigin, callback) 
  33286. {
  33287. var contextId;
  33288. if (typeof options === "object" && options["useContentScriptContext"]) {
  33289. var mainFrame = WebInspector.resourceTreeModel.mainFrame;
  33290. if (!mainFrame)
  33291. return this._status.E_FAILED("main frame not available yet");
  33292. var context = WebInspector.runtimeModel.contextByFrameAndSecurityOrigin(mainFrame, securityOrigin);
  33293. if (!context)
  33294. return this._status.E_NOTFOUND(securityOrigin);
  33295. contextId = context.id;
  33296. }
  33297. RuntimeAgent.evaluate(expression, "extension", exposeCommandLineAPI, true, contextId, returnByValue, false, callback);
  33298. }
  33299. }
  33300.  
  33301.  
  33302. WebInspector.ExtensionStatus = function()
  33303. {
  33304. function makeStatus(code, description)
  33305. {
  33306. var details = Array.prototype.slice.call(arguments, 2);
  33307. var status = { code: code, description: description, details: details };
  33308. if (code !== "OK") {
  33309. status.isError = true;
  33310. console.log("Extension server error: " + String.vsprintf(description, details));
  33311. }
  33312. return status;
  33313. }
  33314.  
  33315. this.OK = makeStatus.bind(null, "OK", "OK");
  33316. this.E_EXISTS = makeStatus.bind(null, "E_EXISTS", "Object already exists: %s");
  33317. this.E_BADARG = makeStatus.bind(null, "E_BADARG", "Invalid argument %s: %s");
  33318. this.E_BADARGTYPE = makeStatus.bind(null, "E_BADARGTYPE", "Invalid type for argument %s: got %s, expected %s");
  33319. this.E_NOTFOUND = makeStatus.bind(null, "E_NOTFOUND", "Object not found: %s");
  33320. this.E_NOTSUPPORTED = makeStatus.bind(null, "E_NOTSUPPORTED", "Object does not support requested operation: %s");
  33321. this.E_FAILED = makeStatus.bind(null, "E_FAILED", "Operation failed: %s");
  33322. }
  33323.  
  33324. WebInspector.addExtensions = function(extensions)
  33325. {
  33326. WebInspector.extensionServer._addExtensions(extensions);
  33327. }
  33328.  
  33329. WebInspector.extensionAPI = {};
  33330. defineCommonExtensionSymbols(WebInspector.extensionAPI);
  33331.  
  33332. WebInspector.extensionServer = new WebInspector.ExtensionServer();
  33333.  
  33334. window.addExtension = function(page, name)
  33335. {
  33336. WebInspector.extensionServer._addExtension({
  33337. startPage: page,
  33338. name: name,
  33339. });
  33340. }
  33341.  
  33342.  
  33343.  
  33344.  
  33345.  
  33346.  
  33347. WebInspector.ExtensionView = function(id, src, className)
  33348. {
  33349. WebInspector.View.call(this);
  33350. this.element.className = "fill";
  33351.  
  33352. this._id = id;
  33353. this._iframe = document.createElement("iframe");
  33354. this._iframe.addEventListener("load", this._onLoad.bind(this), false);
  33355. this._iframe.src = src;
  33356. this._iframe.className = className;
  33357. this.setDefaultFocusedElement(this._iframe);
  33358.  
  33359. this.element.appendChild(this._iframe);
  33360. }
  33361.  
  33362. WebInspector.ExtensionView.prototype = {
  33363. wasShown: function()
  33364. {
  33365. if (typeof this._frameIndex === "number")
  33366. WebInspector.extensionServer.notifyViewShown(this._id, this._frameIndex);
  33367. },
  33368.  
  33369. willHide: function()
  33370. {
  33371. if (typeof this._frameIndex === "number")
  33372. WebInspector.extensionServer.notifyViewHidden(this._id);
  33373. },
  33374.  
  33375. _onLoad: function()
  33376. {
  33377. this._frameIndex = Array.prototype.indexOf.call(window.frames, this._iframe.contentWindow);
  33378. if (this.isShowing())
  33379. WebInspector.extensionServer.notifyViewShown(this._id, this._frameIndex);
  33380. },
  33381.  
  33382. __proto__: WebInspector.View.prototype
  33383. }
  33384.  
  33385.  
  33386. WebInspector.ExtensionNotifierView = function(id)
  33387. {
  33388. WebInspector.View.call(this);
  33389.  
  33390. this._id = id;
  33391. }
  33392.  
  33393. WebInspector.ExtensionNotifierView.prototype = {
  33394. wasShown: function()
  33395. {
  33396. WebInspector.extensionServer.notifyViewShown(this._id);
  33397. },
  33398.  
  33399. willHide: function()
  33400. {
  33401. WebInspector.extensionServer.notifyViewHidden(this._id);
  33402. },
  33403.  
  33404. __proto__: WebInspector.View.prototype
  33405. }
  33406.  
  33407.  
  33408.  
  33409.  
  33410.  
  33411.  
  33412. WebInspector.ExtensionPanel = function(id, pageURL)
  33413. {
  33414. WebInspector.Panel.call(this, id);
  33415. this.setHideOnDetach();
  33416. this._statusBarItems = [];
  33417. var extensionView = new WebInspector.ExtensionView(id, pageURL, "extension panel");
  33418. extensionView.show(this.element);
  33419. this.setDefaultFocusedElement(extensionView.defaultFocusedElement());
  33420. }
  33421.  
  33422. WebInspector.ExtensionPanel.prototype = {
  33423. defaultFocusedElement: function()
  33424. {
  33425. return WebInspector.View.prototype.defaultFocusedElement.call(this);
  33426. },
  33427.  
  33428. get statusBarItems()
  33429. {
  33430. return this._statusBarItems;
  33431. },
  33432.  
  33433.  
  33434. addStatusBarItem: function(element)
  33435. {
  33436. this._statusBarItems.push(element);
  33437. },
  33438.  
  33439. searchCanceled: function(startingNewSearch)
  33440. {
  33441. WebInspector.extensionServer.notifySearchAction(this.name, WebInspector.extensionAPI.panels.SearchAction.CancelSearch);
  33442. WebInspector.Panel.prototype.searchCanceled.apply(this, arguments);
  33443. },
  33444.  
  33445.  
  33446. performSearch: function(query)
  33447. {
  33448. WebInspector.extensionServer.notifySearchAction(this.name, WebInspector.extensionAPI.panels.SearchAction.PerformSearch, query);
  33449. WebInspector.Panel.prototype.performSearch.apply(this, arguments);
  33450. },
  33451.  
  33452. jumpToNextSearchResult: function()
  33453. {
  33454. WebInspector.extensionServer.notifySearchAction(this.name, WebInspector.extensionAPI.panels.SearchAction.NextSearchResult);
  33455. WebInspector.Panel.prototype.jumpToNextSearchResult.call(this);
  33456. },
  33457.  
  33458. jumpToPreviousSearchResult: function()
  33459. {
  33460. WebInspector.extensionServer.notifySearchAction(this.name, WebInspector.extensionAPI.panels.SearchAction.PreviousSearchResult);
  33461. WebInspector.Panel.prototype.jumpToPreviousSearchResult.call(this);
  33462. },
  33463.  
  33464. __proto__: WebInspector.Panel.prototype
  33465. }
  33466.  
  33467.  
  33468. WebInspector.ExtensionButton = function(id, iconURL, tooltip, disabled)
  33469. {
  33470. this._id = id;
  33471. this.element = document.createElement("button");
  33472. this.element.className = "status-bar-item extension";
  33473. this.element.addEventListener("click", this._onClicked.bind(this), false);
  33474. this.update(iconURL, tooltip, disabled);
  33475. }
  33476.  
  33477. WebInspector.ExtensionButton.prototype = {
  33478.  
  33479. update: function(iconURL, tooltip, disabled)
  33480. {
  33481. if (typeof iconURL === "string")
  33482. this.element.style.backgroundImage = "url(" + iconURL + ")";
  33483. if (typeof tooltip === "string")
  33484. this.element.title = tooltip;
  33485. if (typeof disabled === "boolean")
  33486. this.element.disabled = disabled;
  33487. },
  33488.  
  33489. _onClicked: function()
  33490. {
  33491. WebInspector.extensionServer.notifyButtonClicked(this._id);
  33492. }
  33493. }
  33494.  
  33495.  
  33496. WebInspector.ExtensionSidebarPane = function(title, id)
  33497. {
  33498. WebInspector.SidebarPane.call(this, title);
  33499. this._id = id;
  33500. }
  33501.  
  33502. WebInspector.ExtensionSidebarPane.prototype = {
  33503.  
  33504. setObject: function(object, title, callback)
  33505. {
  33506. this._createObjectPropertiesView();
  33507. this._setObject(WebInspector.RemoteObject.fromLocalObject(object), title, callback);
  33508. },
  33509.  
  33510.  
  33511. setExpression: function(expression, title, evaluateOptions, securityOrigin, callback)
  33512. {
  33513. this._createObjectPropertiesView();
  33514. return WebInspector.extensionServer.evaluate(expression, true, false, evaluateOptions, securityOrigin, this._onEvaluate.bind(this, title, callback));
  33515. },
  33516.  
  33517.  
  33518. setPage: function(url)
  33519. {
  33520. if (this._objectPropertiesView) {
  33521. this._objectPropertiesView.detach();
  33522. delete this._objectPropertiesView;
  33523. }
  33524. if (this._extensionView)
  33525. this._extensionView.detach(true);
  33526.  
  33527. this._extensionView = new WebInspector.ExtensionView(this._id, url, "extension fill");
  33528. this._extensionView.show(this.bodyElement);
  33529.  
  33530. if (!this.bodyElement.style.height)
  33531. this.setHeight("150px");
  33532. },
  33533.  
  33534.  
  33535. setHeight: function(height)
  33536. {
  33537. this.bodyElement.style.height = height;
  33538. },
  33539.  
  33540.  
  33541. _onEvaluate: function(title, callback, error, result, wasThrown)
  33542. {
  33543. if (error)
  33544. callback(error.toString());
  33545. else
  33546. this._setObject(WebInspector.RemoteObject.fromPayload(result), title, callback);
  33547. },
  33548.  
  33549. _createObjectPropertiesView: function()
  33550. {
  33551. if (this._objectPropertiesView)
  33552. return;
  33553. if (this._extensionView) {
  33554. this._extensionView.detach(true);
  33555. delete this._extensionView;
  33556. }
  33557. this._objectPropertiesView = new WebInspector.ExtensionNotifierView(this._id);
  33558. this._objectPropertiesView.show(this.bodyElement);
  33559. },
  33560.  
  33561.  
  33562. _setObject: function(object, title, callback)
  33563. {
  33564.  
  33565. if (!this._objectPropertiesView) {
  33566. callback("operation cancelled");
  33567. return;
  33568. }
  33569. this._objectPropertiesView.element.removeChildren();
  33570. var section = new WebInspector.ObjectPropertiesSection(object, title);
  33571. if (!title)
  33572. section.headerElement.addStyleClass("hidden");
  33573. section.expanded = true;
  33574. section.editable = false;
  33575. this._objectPropertiesView.element.appendChild(section.element);
  33576. callback();
  33577. },
  33578.  
  33579. __proto__: WebInspector.SidebarPane.prototype
  33580. }
  33581.  
  33582.  
  33583.  
  33584.  
  33585.  
  33586.  
  33587. WebInspector.EmptyView = function(text)
  33588. {
  33589. WebInspector.View.call(this);
  33590. this._text = text;
  33591. }
  33592.  
  33593. WebInspector.EmptyView.prototype = {
  33594. wasShown: function()
  33595. {
  33596. this.element.className = "storage-empty-view";
  33597. this.element.textContent = this._text;
  33598. },
  33599.  
  33600. set text(text)
  33601. {
  33602. this._text = text;
  33603. if (this.isShowing())
  33604. this.element.textContent = this._text;
  33605. },
  33606.  
  33607. __proto__: WebInspector.View.prototype
  33608. }
  33609.  
  33610.  
  33611.  
  33612.  
  33613.  
  33614.  
  33615.  
  33616. WebInspector.Formatter = function()
  33617. {
  33618. }
  33619.  
  33620.  
  33621. WebInspector.Formatter.createFormatter = function(contentType)
  33622. {
  33623. if (contentType === WebInspector.resourceTypes.Script || contentType === WebInspector.resourceTypes.Document)
  33624. return new WebInspector.ScriptFormatter();
  33625. return new WebInspector.IdentityFormatter();
  33626. }
  33627.  
  33628.  
  33629. WebInspector.Formatter.locationToPosition = function(lineEndings, lineNumber, columnNumber)
  33630. {
  33631. var position = lineNumber ? lineEndings[lineNumber - 1] + 1 : 0;
  33632. return position + columnNumber;
  33633. }
  33634.  
  33635.  
  33636. WebInspector.Formatter.positionToLocation = function(lineEndings, position)
  33637. {
  33638. var lineNumber = lineEndings.upperBound(position - 1);
  33639. if (!lineNumber)
  33640. var columnNumber = position;
  33641. else
  33642. var columnNumber = position - lineEndings[lineNumber - 1] - 1;
  33643. return [lineNumber, columnNumber];
  33644. }
  33645.  
  33646. WebInspector.Formatter.prototype = {
  33647.  
  33648. formatContent: function(mimeType, content, callback)
  33649. {
  33650. }
  33651. }
  33652.  
  33653.  
  33654. WebInspector.ScriptFormatter = function()
  33655. {
  33656. this._tasks = [];
  33657. }
  33658.  
  33659. WebInspector.ScriptFormatter.prototype = {
  33660.  
  33661. formatContent: function(mimeType, content, callback)
  33662. {
  33663. content = content.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/^\uFEFF/, '');
  33664. const method = "format";
  33665. var parameters = { mimeType: mimeType, content: content, indentString: WebInspector.settings.textEditorIndent.get() };
  33666. this._tasks.push({ data: parameters, callback: callback });
  33667. this._worker.postMessage({ method: method, params: parameters });
  33668. },
  33669.  
  33670. _didFormatContent: function(event)
  33671. {
  33672. var task = this._tasks.shift();
  33673. var originalContent = task.data.content;
  33674. var formattedContent = event.data.content;
  33675. var mapping = event.data["mapping"];
  33676. var sourceMapping = new WebInspector.FormatterSourceMappingImpl(originalContent.lineEndings(), formattedContent.lineEndings(), mapping);
  33677. task.callback(formattedContent, sourceMapping);
  33678. },
  33679.  
  33680.  
  33681. get _worker()
  33682. {
  33683. if (!this._cachedWorker) {
  33684. this._cachedWorker = new Worker("ScriptFormatterWorker.js");
  33685. this._cachedWorker.onmessage =   (this._didFormatContent.bind(this));
  33686. }
  33687. return this._cachedWorker;
  33688. }
  33689. }
  33690.  
  33691.  
  33692. WebInspector.IdentityFormatter = function()
  33693. {
  33694. this._tasks = [];
  33695. }
  33696.  
  33697. WebInspector.IdentityFormatter.prototype = {
  33698.  
  33699. formatContent: function(mimeType, content, callback)
  33700. {
  33701. callback(content, new WebInspector.IdentityFormatterSourceMapping());
  33702. }
  33703. }
  33704.  
  33705.  
  33706. WebInspector.FormatterMappingPayload = function()
  33707. {
  33708. this.original = [];
  33709. this.formatted = [];
  33710. }
  33711.  
  33712.  
  33713. WebInspector.FormatterSourceMapping = function()
  33714. {
  33715. }
  33716.  
  33717. WebInspector.FormatterSourceMapping.prototype = {
  33718.  
  33719. originalToFormatted: function(lineNumber, columnNumber) { },
  33720.  
  33721.  
  33722. formattedToOriginal: function(lineNumber, columnNumber) { }
  33723. }
  33724.  
  33725.  
  33726. WebInspector.IdentityFormatterSourceMapping = function()
  33727. {
  33728. }
  33729.  
  33730. WebInspector.IdentityFormatterSourceMapping.prototype = {
  33731.  
  33732. originalToFormatted: function(lineNumber, columnNumber)
  33733. {
  33734. return [lineNumber, columnNumber || 0]; 
  33735. },
  33736.  
  33737.  
  33738. formattedToOriginal: function(lineNumber, columnNumber)
  33739. {
  33740. return [lineNumber, columnNumber || 0];
  33741. }
  33742. }
  33743.  
  33744.  
  33745. WebInspector.FormatterSourceMappingImpl = function(originalLineEndings, formattedLineEndings, mapping)
  33746. {
  33747. this._originalLineEndings = originalLineEndings;
  33748. this._formattedLineEndings = formattedLineEndings;
  33749. this._mapping = mapping;
  33750. }
  33751.  
  33752. WebInspector.FormatterSourceMappingImpl.prototype = {
  33753.  
  33754. originalToFormatted: function(lineNumber, columnNumber)
  33755. {
  33756. var originalPosition = WebInspector.Formatter.locationToPosition(this._originalLineEndings, lineNumber, columnNumber || 0);
  33757. var formattedPosition = this._convertPosition(this._mapping.original, this._mapping.formatted, originalPosition || 0);
  33758. return WebInspector.Formatter.positionToLocation(this._formattedLineEndings, formattedPosition);
  33759. },
  33760.  
  33761.  
  33762. formattedToOriginal: function(lineNumber, columnNumber)
  33763. {
  33764. var formattedPosition = WebInspector.Formatter.locationToPosition(this._formattedLineEndings, lineNumber, columnNumber || 0);
  33765. var originalPosition = this._convertPosition(this._mapping.formatted, this._mapping.original, formattedPosition);
  33766. return WebInspector.Formatter.positionToLocation(this._originalLineEndings, originalPosition || 0);
  33767. },
  33768.  
  33769.  
  33770. _convertPosition: function(positions1, positions2, position)
  33771. {
  33772. var index = positions1.upperBound(position) - 1;
  33773. var convertedPosition = positions2[index] + position - positions1[index];
  33774. if (index < positions2.length - 1 && convertedPosition > positions2[index + 1])
  33775. convertedPosition = positions2[index + 1];
  33776. return convertedPosition;
  33777. }
  33778. }
  33779.  
  33780.  
  33781.  
  33782.  
  33783.  
  33784.  
  33785. WebInspector.DOMSyntaxHighlighter = function(mimeType, stripExtraWhitespace)
  33786. {
  33787. this._tokenizer = WebInspector.SourceTokenizer.Registry.getInstance().getTokenizer(mimeType);
  33788. this._stripExtraWhitespace = stripExtraWhitespace;
  33789. }
  33790.  
  33791. WebInspector.DOMSyntaxHighlighter.prototype = {
  33792. createSpan: function(content, className)
  33793. {
  33794. var span = document.createElement("span");
  33795. span.className = "webkit-" + className;
  33796. if (this._stripExtraWhitespace)
  33797. content = content.replace(/^[\n\r]*/, "").replace(/\s*$/, "");
  33798. span.appendChild(document.createTextNode(content));
  33799. return span;
  33800. },
  33801.  
  33802. syntaxHighlightNode: function(node)
  33803. {
  33804. this._tokenizer.condition = this._tokenizer.createInitialCondition();
  33805. var lines = node.textContent.split("\n");
  33806. node.removeChildren();
  33807.  
  33808. for (var i = lines[0].length ? 0 : 1; i < lines.length; ++i) {
  33809. var line = lines[i];
  33810. var plainTextStart = 0;
  33811. this._tokenizer.line = line;
  33812. var column = 0;
  33813. do {
  33814. var newColumn = this._tokenizer.nextToken(column);
  33815. var tokenType = this._tokenizer.tokenType;
  33816. if (tokenType) {
  33817. if (column > plainTextStart) {
  33818. var plainText = line.substring(plainTextStart, column);
  33819. node.appendChild(document.createTextNode(plainText));
  33820. }
  33821. var token = line.substring(column, newColumn);
  33822. node.appendChild(this.createSpan(token, tokenType));
  33823. plainTextStart = newColumn;
  33824. }
  33825. column = newColumn;
  33826. } while (column < line.length)
  33827.  
  33828. if (plainTextStart < line.length) {
  33829. var plainText = line.substring(plainTextStart, line.length);
  33830. node.appendChild(document.createTextNode(plainText));
  33831. }
  33832. if (i < lines.length - 1)
  33833. node.appendChild(document.createElement("br"));
  33834. }
  33835. }
  33836. }
  33837.  
  33838.  
  33839.  
  33840.  
  33841.  
  33842.  
  33843. WebInspector.TextRange = function(startLine, startColumn, endLine, endColumn)
  33844. {
  33845. this.startLine = startLine;
  33846. this.startColumn = startColumn;
  33847. this.endLine = endLine;
  33848. this.endColumn = endColumn;
  33849. }
  33850.  
  33851. WebInspector.TextRange.createFromLocation = function(line, column)
  33852. {
  33853. return new WebInspector.TextRange(line, column, line, column);
  33854. }
  33855.  
  33856.  
  33857. WebInspector.TextRange.fromObject = function (serializedTextRange)
  33858. {
  33859. return new WebInspector.TextRange(serializedTextRange.startLine, serializedTextRange.startColumn, serializedTextRange.endLine, serializedTextRange.endColumn);
  33860. }
  33861.  
  33862. WebInspector.TextRange.prototype = {
  33863.  
  33864. isEmpty: function()
  33865. {
  33866. return this.startLine === this.endLine && this.startColumn === this.endColumn;
  33867. },
  33868.  
  33869.  
  33870. get linesCount()
  33871. {
  33872. return this.endLine - this.startLine;
  33873. },
  33874.  
  33875. collapseToEnd: function()
  33876. {
  33877. return new WebInspector.TextRange(this.endLine, this.endColumn, this.endLine, this.endColumn);
  33878. },
  33879.  
  33880.  
  33881. normalize: function()
  33882. {
  33883. if (this.startLine > this.endLine || (this.startLine === this.endLine && this.startColumn > this.endColumn))
  33884. return new WebInspector.TextRange(this.endLine, this.endColumn, this.startLine, this.startColumn);
  33885. else
  33886. return this.clone();
  33887. },
  33888.  
  33889.  
  33890. clone: function()
  33891. {
  33892. return new WebInspector.TextRange(this.startLine, this.startColumn, this.endLine, this.endColumn);
  33893. },
  33894.  
  33895.  
  33896. serializeToObject: function()
  33897. {
  33898. var serializedTextRange = {};
  33899. serializedTextRange.startLine = this.startLine;
  33900. serializedTextRange.startColumn = this.startColumn;
  33901. serializedTextRange.endLine = this.endLine;
  33902. serializedTextRange.endColumn = this.endColumn;
  33903. return serializedTextRange;
  33904. },
  33905.  
  33906.  
  33907. compareTo: function(other)
  33908. {
  33909. if (this.startLine > other.startLine)
  33910. return 1;
  33911. if (this.startLine < other.startLine)
  33912. return -1;
  33913. if (this.startColumn > other.startColumn)
  33914. return 1;
  33915. if (this.startColumn < other.startColumn)
  33916. return -1;
  33917. return 0;
  33918. },
  33919.  
  33920.  
  33921. shift: function(lineOffset)
  33922. {
  33923. return new WebInspector.TextRange(this.startLine + lineOffset, this.startColumn, this.endLine + lineOffset, this.endColumn);
  33924. },
  33925.  
  33926. toString: function()
  33927. {
  33928. return JSON.stringify(this);
  33929. }
  33930. }
  33931.  
  33932.  
  33933. WebInspector.TextEditorCommand = function(newRange, originalText)
  33934. {
  33935. this.newRange = newRange;
  33936. this.originalText = originalText;
  33937. }
  33938.  
  33939.  
  33940. WebInspector.TextEditorModel = function()
  33941. {
  33942. this._lines = [""];
  33943. this._attributes = [];
  33944.  
  33945. this._undoStack = [];
  33946. this._noPunctuationRegex = /[^ !%&()*+,-.:;<=>?\[\]\^{|}~]+/;
  33947. this._lineBreak = "\n";
  33948. }
  33949.  
  33950. WebInspector.TextEditorModel.Indent = {
  33951. TwoSpaces: "  ",
  33952. FourSpaces: "    ",
  33953. EightSpaces: "        ",
  33954. TabCharacter: "\t"
  33955. }
  33956.  
  33957. WebInspector.TextEditorModel.Events = {
  33958. TextChanged: "TextChanged"
  33959. }
  33960.  
  33961. WebInspector.TextEditorModel.endsWithBracketRegex = /[{(\[]\s*$/;
  33962.  
  33963. WebInspector.TextEditorModel.prototype = {
  33964.  
  33965. get linesCount()
  33966. {
  33967. return this._lines.length;
  33968. },
  33969.  
  33970.  
  33971. text: function()
  33972. {
  33973. return this._lines.join(this._lineBreak);
  33974. },
  33975.  
  33976.  
  33977. range: function()
  33978. {
  33979. return new WebInspector.TextRange(0, 0, this._lines.length - 1, this._lines[this._lines.length - 1].length);
  33980. },
  33981.  
  33982.  
  33983. get lineBreak()
  33984. {
  33985. return this._lineBreak;
  33986. },
  33987.  
  33988.  
  33989. line: function(lineNumber)
  33990. {
  33991. if (lineNumber >= this._lines.length)
  33992. throw "Out of bounds:" + lineNumber;
  33993. return this._lines[lineNumber];
  33994. },
  33995.  
  33996.  
  33997. lineLength: function(lineNumber)
  33998. {
  33999. return this._lines[lineNumber].length;
  34000. },
  34001.  
  34002.  
  34003. setText: function(text)
  34004. {
  34005. this._resetUndoStack();
  34006. text = text || "";
  34007. var range = this.range();
  34008. this._lineBreak = /\r\n/.test(text) ? "\r\n" : "\n";
  34009. var newRange = this._innerSetText(range, text);
  34010. this.dispatchEventToListeners(WebInspector.TextEditorModel.Events.TextChanged, { oldRange: range, newRange: newRange});
  34011. },
  34012.  
  34013.  
  34014. editRange: function(range, text)
  34015. {   
  34016. if (this._lastEditedRange && (!text || text.indexOf("\n") !== -1 || this._lastEditedRange.endLine !== range.startLine || this._lastEditedRange.endColumn !== range.startColumn))
  34017. this._markUndoableState();
  34018. return this._innerEditRange(range, text);
  34019. },
  34020.  
  34021.  
  34022. _innerEditRange: function(range, text)
  34023. {
  34024. var originalText = this.copyRange(range);
  34025. this._lastEditedRange = range;
  34026. var newRange = range;
  34027. if (text !== originalText) {
  34028. newRange = this._innerSetText(range, text);
  34029. this._pushUndoableCommand(newRange, originalText);
  34030. }
  34031.  
  34032. this.dispatchEventToListeners(WebInspector.TextEditorModel.Events.TextChanged, { oldRange: range, newRange: newRange, editRange: true });
  34033. return newRange;
  34034. },
  34035.  
  34036.  
  34037. _innerSetText: function(range, text)
  34038. {
  34039. this._eraseRange(range);
  34040. if (text === "")
  34041. return new WebInspector.TextRange(range.startLine, range.startColumn, range.startLine, range.startColumn);
  34042.  
  34043. var newLines = text.split(/\r?\n/);
  34044.  
  34045. var prefix = this._lines[range.startLine].substring(0, range.startColumn);
  34046. var suffix = this._lines[range.startLine].substring(range.startColumn);
  34047.  
  34048. var postCaret = prefix.length;
  34049.  
  34050. if (newLines.length === 1) {
  34051. this._setLine(range.startLine, prefix + newLines[0] + suffix);
  34052. postCaret += newLines[0].length;
  34053. } else {
  34054. this._setLine(range.startLine, prefix + newLines[0]);
  34055. this._insertLines(range, newLines);
  34056. this._setLine(range.startLine + newLines.length - 1, newLines[newLines.length - 1] + suffix);
  34057. postCaret = newLines[newLines.length - 1].length;
  34058. }
  34059.  
  34060. return new WebInspector.TextRange(range.startLine, range.startColumn,
  34061. range.startLine + newLines.length - 1, postCaret);
  34062. },
  34063.  
  34064.  
  34065. _insertLines: function(range, newLines)
  34066. {
  34067. var lines = new Array(this._lines.length + newLines.length - 1);
  34068. for (var i = 0; i <= range.startLine; ++i)
  34069. lines[i] = this._lines[i];
  34070.  
  34071. for (var i = 1; i < newLines.length; ++i)
  34072. lines[range.startLine + i] = newLines[i];
  34073. for (var i = range.startLine + newLines.length; i < lines.length; ++i)
  34074. lines[i] = this._lines[i - newLines.length + 1];
  34075. this._lines = lines;
  34076.  
  34077.  
  34078. var attributes = new Array(lines.length);
  34079. var insertionIndex = range.startColumn ? range.startLine + 1 : range.startLine;
  34080. for (var i = 0; i < insertionIndex; ++i)
  34081. attributes[i] = this._attributes[i];
  34082. for (var i = insertionIndex + newLines.length - 1; i < attributes.length; ++i)
  34083. attributes[i] = this._attributes[i - newLines.length + 1];
  34084. this._attributes = attributes;
  34085. },
  34086.  
  34087.  
  34088. _eraseRange: function(range)
  34089. {
  34090. if (range.isEmpty())
  34091. return;
  34092.  
  34093. var prefix = this._lines[range.startLine].substring(0, range.startColumn);
  34094. var suffix = this._lines[range.endLine].substring(range.endColumn);
  34095.  
  34096. if (range.endLine > range.startLine) {
  34097. this._lines.splice(range.startLine + 1, range.endLine - range.startLine);
  34098.  
  34099. this._attributes.splice(range.startColumn ? range.startLine + 1 : range.startLine, range.endLine - range.startLine);
  34100. }
  34101. this._setLine(range.startLine, prefix + suffix);
  34102. },
  34103.  
  34104.  
  34105. _setLine: function(lineNumber, text)
  34106. {
  34107. this._lines[lineNumber] = text;
  34108. },
  34109.  
  34110.  
  34111. wordRange: function(lineNumber, column)
  34112. {
  34113. return new WebInspector.TextRange(lineNumber, this.wordStart(lineNumber, column, true), lineNumber, this.wordEnd(lineNumber, column, true));
  34114. },
  34115.  
  34116.  
  34117. wordStart: function(lineNumber, column, gapless)
  34118. {
  34119. var line = this._lines[lineNumber];
  34120. var prefix = line.substring(0, column).split("").reverse().join("");
  34121. var prefixMatch = this._noPunctuationRegex.exec(prefix);
  34122. return prefixMatch && (!gapless || prefixMatch.index === 0) ? column - prefixMatch.index - prefixMatch[0].length : column;
  34123. },
  34124.  
  34125.  
  34126. wordEnd: function(lineNumber, column, gapless)
  34127. {
  34128. var line = this._lines[lineNumber];
  34129. var suffix = line.substring(column);
  34130. var suffixMatch = this._noPunctuationRegex.exec(suffix);
  34131. return suffixMatch && (!gapless || suffixMatch.index === 0) ? column + suffixMatch.index + suffixMatch[0].length : column;
  34132. },
  34133.  
  34134.  
  34135. copyRange: function(range)
  34136. {
  34137. if (!range)
  34138. range = this.range();
  34139.  
  34140. var clip = [];
  34141. if (range.startLine === range.endLine) {
  34142. clip.push(this._lines[range.startLine].substring(range.startColumn, range.endColumn));
  34143. return clip.join(this._lineBreak);
  34144. }
  34145. clip.push(this._lines[range.startLine].substring(range.startColumn));
  34146. for (var i = range.startLine + 1; i < range.endLine; ++i)
  34147. clip.push(this._lines[i]);
  34148. clip.push(this._lines[range.endLine].substring(0, range.endColumn));
  34149. return clip.join(this._lineBreak);
  34150. },
  34151.  
  34152.  
  34153. setAttribute: function(line, name, value)
  34154. {
  34155. var attrs = this._attributes[line];
  34156. if (!attrs) {
  34157. attrs = {};
  34158. this._attributes[line] = attrs;
  34159. }
  34160. attrs[name] = value;
  34161. },
  34162.  
  34163.  
  34164. getAttribute: function(line, name)
  34165. {
  34166. var attrs = this._attributes[line];
  34167. return attrs ? attrs[name] : null;
  34168. },
  34169.  
  34170.  
  34171. removeAttribute: function(line, name)
  34172. {
  34173. var attrs = this._attributes[line];
  34174. if (attrs)
  34175. delete attrs[name];
  34176. },
  34177.  
  34178.  
  34179. _pushUndoableCommand: function(newRange, originalText)
  34180. {
  34181. var command = new WebInspector.TextEditorCommand(newRange.clone(), originalText);
  34182. if (this._inUndo)
  34183. this._redoStack.push(command);
  34184. else {
  34185. if (!this._inRedo)
  34186. this._redoStack = [];
  34187. this._undoStack.push(command);
  34188. }
  34189. return command;
  34190. },
  34191.  
  34192.  
  34193. undo: function()
  34194. {
  34195. if (!this._undoStack.length)
  34196. return null;
  34197.  
  34198. this._markRedoableState();
  34199.  
  34200. this._inUndo = true;
  34201. var range = this._doUndo(this._undoStack);
  34202. delete this._inUndo;
  34203.  
  34204. return range;
  34205. },
  34206.  
  34207.  
  34208. redo: function()
  34209. {
  34210. if (!this._redoStack || !this._redoStack.length)
  34211. return null;
  34212. this._markUndoableState();
  34213.  
  34214. this._inRedo = true;
  34215. var range = this._doUndo(this._redoStack);
  34216. delete this._inRedo;
  34217.  
  34218. return range;
  34219. },
  34220.  
  34221.  
  34222. _doUndo: function(stack)
  34223. {
  34224. var range = null;
  34225. for (var i = stack.length - 1; i >= 0; --i) {
  34226. var command = stack[i];
  34227. stack.length = i;
  34228. range = this._innerEditRange(command.newRange, command.originalText);
  34229. if (i > 0 && stack[i - 1].explicit)
  34230. return range;
  34231. }
  34232. return range;
  34233. },
  34234.  
  34235. _markUndoableState: function()
  34236. {
  34237. if (this._undoStack.length)
  34238. this._undoStack[this._undoStack.length - 1].explicit = true;
  34239. },
  34240.  
  34241. _markRedoableState: function()
  34242. {
  34243. if (this._redoStack.length)
  34244. this._redoStack[this._redoStack.length - 1].explicit = true;
  34245. },
  34246.  
  34247. _resetUndoStack: function()
  34248. {
  34249. this._undoStack = [];
  34250. },
  34251.  
  34252.  
  34253. indentLines: function(range)
  34254. {
  34255. this._markUndoableState();
  34256.  
  34257. var indent = WebInspector.settings.textEditorIndent.get();
  34258. var newRange = range.clone();
  34259.  
  34260. if (range.startColumn)
  34261. newRange.startColumn += indent.length;
  34262.  
  34263. var indentEndLine = range.endLine;
  34264. if (range.endColumn)
  34265. newRange.endColumn += indent.length;
  34266. else
  34267. indentEndLine--;
  34268.  
  34269. for (var lineNumber = range.startLine; lineNumber <= indentEndLine; lineNumber++)
  34270. this._innerEditRange(WebInspector.TextRange.createFromLocation(lineNumber, 0), indent);
  34271.  
  34272. return newRange;
  34273. },
  34274.  
  34275.  
  34276. unindentLines: function(range)
  34277. {
  34278. this._markUndoableState();
  34279.  
  34280. var indent = WebInspector.settings.textEditorIndent.get();
  34281. var indentLength = indent === WebInspector.TextEditorModel.Indent.TabCharacter ? 4 : indent.length;
  34282. var lineIndentRegex = new RegExp("^ {1," + indentLength + "}");
  34283. var newRange = range.clone();
  34284.  
  34285. var indentEndLine = range.endLine;
  34286. if (!range.endColumn)
  34287. indentEndLine--;
  34288.  
  34289. for (var lineNumber = range.startLine; lineNumber <= indentEndLine; lineNumber++) {
  34290. var line = this.line(lineNumber);
  34291. var firstCharacter = line.charAt(0);
  34292. var lineIndentLength;
  34293.  
  34294. if (firstCharacter === " ")
  34295. lineIndentLength = line.match(lineIndentRegex)[0].length;
  34296. else if (firstCharacter === "\t")
  34297. lineIndentLength = 1;
  34298. else
  34299. continue;
  34300.  
  34301. this._innerEditRange(new WebInspector.TextRange(lineNumber, 0, lineNumber, lineIndentLength), "");
  34302.  
  34303. if (lineNumber === range.startLine)
  34304. newRange.startColumn = Math.max(0, newRange.startColumn - lineIndentLength);
  34305. if (lineNumber === range.endLine)
  34306. newRange.endColumn = Math.max(0, newRange.endColumn - lineIndentLength);
  34307. }
  34308.  
  34309. return newRange;
  34310. },
  34311.  
  34312.  
  34313. slice: function(from, to)
  34314. {
  34315. var textModel = new WebInspector.TextEditorModel();
  34316. textModel._lines = this._lines.slice(from, to);
  34317. textModel._lineBreak = this._lineBreak;
  34318. return textModel;
  34319. },
  34320.  
  34321.  
  34322. growRangeLeft: function(range)
  34323. {
  34324. var result = range.clone();
  34325. if (result.startColumn)
  34326. --result.startColumn;
  34327. else if (result.startLine)
  34328. result.startColumn = this.lineLength(--result.startLine);
  34329. return result;
  34330. },
  34331.  
  34332.  
  34333. growRangeRight: function(range)
  34334. {
  34335. var result = range.clone();
  34336. if (result.endColumn < this.lineLength(result.endLine))
  34337. ++result.endColumn;
  34338. else if (result.endLine < this.linesCount) {
  34339. result.endColumn = 0;
  34340. ++result.endLine;
  34341. }
  34342. return result;
  34343. },
  34344.  
  34345. __proto__: WebInspector.Object.prototype
  34346. }
  34347.  
  34348.  
  34349.  
  34350.  
  34351.  
  34352.  
  34353. WebInspector.TextEditorHighlighter = function(textModel, damageCallback)
  34354. {
  34355. this._textModel = textModel;
  34356. this._tokenizer = WebInspector.SourceTokenizer.Registry.getInstance().getTokenizer("text/html");
  34357. this._damageCallback = damageCallback;
  34358. this._highlightChunkLimit = 1000;
  34359. }
  34360.  
  34361. WebInspector.TextEditorHighlighter._MaxLineCount = 10000;
  34362.  
  34363. WebInspector.TextEditorHighlighter.prototype = {
  34364. set mimeType(mimeType)
  34365. {
  34366. var tokenizer = WebInspector.SourceTokenizer.Registry.getInstance().getTokenizer(mimeType);
  34367. if (tokenizer)
  34368. this._tokenizer = tokenizer;
  34369. },
  34370.  
  34371. set highlightChunkLimit(highlightChunkLimit)
  34372. {
  34373. this._highlightChunkLimit = highlightChunkLimit;
  34374. },
  34375.  
  34376.  
  34377. highlight: function(endLine, forceRun)
  34378. {
  34379. if (this._textModel.linesCount > WebInspector.TextEditorHighlighter._MaxLineCount)
  34380. return;
  34381.  
  34382.  
  34383. var state = this._textModel.getAttribute(endLine - 1, "highlight");
  34384. if (state && state.postConditionStringified) {
  34385.  
  34386. return;
  34387. }
  34388.  
  34389. this._requestedEndLine = endLine;
  34390.  
  34391. if (this._highlightTimer && !forceRun) {
  34392.  
  34393. return;
  34394. }
  34395.  
  34396.  
  34397. var startLine = endLine;
  34398. while (startLine > 0) {
  34399. state = this._textModel.getAttribute(startLine - 1, "highlight");
  34400. if (state && state.postConditionStringified)
  34401. break;
  34402. startLine--;
  34403. }
  34404.  
  34405.  
  34406. this._highlightInChunks(startLine, endLine);
  34407. },
  34408.  
  34409. updateHighlight: function(startLine, endLine)
  34410. {
  34411. if (this._textModel.linesCount > WebInspector.TextEditorHighlighter._MaxLineCount)
  34412. return;
  34413.  
  34414.  
  34415. this._clearHighlightState(startLine);
  34416.  
  34417. if (startLine) {
  34418. var state = this._textModel.getAttribute(startLine - 1, "highlight");
  34419. if (!state || !state.postConditionStringified) {
  34420.  
  34421. return false;
  34422. }
  34423. }
  34424.  
  34425. var restored = this._highlightLines(startLine, endLine);
  34426. if (!restored) {
  34427. for (var i = this._lastHighlightedLine; i < this._textModel.linesCount; ++i) {
  34428. var state = this._textModel.getAttribute(i, "highlight");
  34429. if (!state && i > endLine)
  34430. break;
  34431. this._textModel.setAttribute(i, "highlight-outdated", state);
  34432. this._textModel.removeAttribute(i, "highlight");
  34433. }
  34434.  
  34435. if (this._highlightTimer) {
  34436. clearTimeout(this._highlightTimer);
  34437. this._requestedEndLine = endLine;
  34438. this._highlightTimer = setTimeout(this._highlightInChunks.bind(this, this._lastHighlightedLine, this._requestedEndLine), 10);
  34439. }
  34440. }
  34441. return restored;
  34442. },
  34443.  
  34444. _highlightInChunks: function(startLine, endLine)
  34445. {
  34446. delete this._highlightTimer;
  34447.  
  34448.  
  34449. var state = this._textModel.getAttribute(this._requestedEndLine - 1, "highlight");
  34450. if (state && state.postConditionStringified)
  34451. return;
  34452.  
  34453. if (this._requestedEndLine !== endLine) {
  34454.  
  34455. this._highlightTimer = setTimeout(this._highlightInChunks.bind(this, startLine, this._requestedEndLine), 100);
  34456. return;
  34457. }
  34458.  
  34459.  
  34460. if (this._requestedEndLine > this._textModel.linesCount)
  34461. this._requestedEndLine = this._textModel.linesCount;
  34462.  
  34463. this._highlightLines(startLine, this._requestedEndLine);
  34464.  
  34465.  
  34466. if (this._lastHighlightedLine < this._requestedEndLine)
  34467. this._highlightTimer = setTimeout(this._highlightInChunks.bind(this, this._lastHighlightedLine, this._requestedEndLine), 10);
  34468. },
  34469.  
  34470. _highlightLines: function(startLine, endLine)
  34471. {
  34472.  
  34473. var state = this._textModel.getAttribute(startLine - 1, "highlight");
  34474. var postConditionStringified = state ? state.postConditionStringified : JSON.stringify(this._tokenizer.createInitialCondition());
  34475.  
  34476. var tokensCount = 0;
  34477. for (var lineNumber = startLine; lineNumber < endLine; ++lineNumber) {
  34478. state = this._selectHighlightState(lineNumber, postConditionStringified);
  34479. if (state.postConditionStringified) {
  34480.  
  34481. postConditionStringified = state.postConditionStringified;
  34482. } else {
  34483. var lastHighlightedColumn = 0;
  34484. if (state.midConditionStringified) {
  34485. lastHighlightedColumn = state.lastHighlightedColumn;
  34486. postConditionStringified = state.midConditionStringified;
  34487. }
  34488.  
  34489. var line = this._textModel.line(lineNumber);
  34490. this._tokenizer.line = line;
  34491. this._tokenizer.condition = JSON.parse(postConditionStringified);
  34492.  
  34493.  
  34494. do {
  34495. var newColumn = this._tokenizer.nextToken(lastHighlightedColumn);
  34496. var tokenType = this._tokenizer.tokenType;
  34497. if (tokenType)
  34498. state[lastHighlightedColumn] = { length: newColumn - lastHighlightedColumn, tokenType: tokenType };
  34499. lastHighlightedColumn = newColumn;
  34500. if (++tokensCount > this._highlightChunkLimit)
  34501. break;
  34502. } while (lastHighlightedColumn < line.length);
  34503.  
  34504. postConditionStringified = JSON.stringify(this._tokenizer.condition);
  34505.  
  34506. if (lastHighlightedColumn < line.length) {
  34507.  
  34508. state.lastHighlightedColumn = lastHighlightedColumn;
  34509. state.midConditionStringified = postConditionStringified;
  34510. break;
  34511. } else {
  34512. delete state.lastHighlightedColumn;
  34513. delete state.midConditionStringified;
  34514. state.postConditionStringified = postConditionStringified;
  34515. }
  34516. }
  34517.  
  34518. var nextLineState = this._textModel.getAttribute(lineNumber + 1, "highlight");
  34519. if (nextLineState && nextLineState.preConditionStringified === state.postConditionStringified) {
  34520.  
  34521. ++lineNumber;
  34522. this._damageCallback(startLine, lineNumber);
  34523.  
  34524.  
  34525. for (; lineNumber < endLine; ++lineNumber) {
  34526. state = this._textModel.getAttribute(lineNumber, "highlight");
  34527. if (!state || !state.postConditionStringified)
  34528. break;
  34529. }
  34530. this._lastHighlightedLine = lineNumber;
  34531. return true;
  34532. }
  34533. }
  34534.  
  34535. this._damageCallback(startLine, lineNumber);
  34536. this._lastHighlightedLine = lineNumber;
  34537. return false;
  34538. },
  34539.  
  34540. _selectHighlightState: function(lineNumber, preConditionStringified)
  34541. {
  34542. var state = this._textModel.getAttribute(lineNumber, "highlight");
  34543. if (state && state.preConditionStringified === preConditionStringified)
  34544. return state;
  34545.  
  34546. var outdatedState = this._textModel.getAttribute(lineNumber, "highlight-outdated");
  34547. if (outdatedState && outdatedState.preConditionStringified === preConditionStringified) {
  34548.  
  34549. this._textModel.setAttribute(lineNumber, "highlight", outdatedState);
  34550. this._textModel.setAttribute(lineNumber, "highlight-outdated", state);
  34551. return outdatedState;
  34552. }
  34553.  
  34554. if (state)
  34555. this._textModel.setAttribute(lineNumber, "highlight-outdated", state);
  34556.  
  34557. state = {};
  34558. state.preConditionStringified = preConditionStringified;
  34559. this._textModel.setAttribute(lineNumber, "highlight", state);
  34560. return state;
  34561. },
  34562.  
  34563. _clearHighlightState: function(lineNumber)
  34564. {
  34565. this._textModel.removeAttribute(lineNumber, "highlight");
  34566. this._textModel.removeAttribute(lineNumber, "highlight-outdated");
  34567. }
  34568. }
  34569.  
  34570.  
  34571.  
  34572.  
  34573.  
  34574.  
  34575.  
  34576. WebInspector.SourceTokenizer = function()
  34577. {
  34578. }
  34579.  
  34580. WebInspector.SourceTokenizer.prototype = {
  34581. set line(line) {
  34582. this._line = line;
  34583. },
  34584.  
  34585. set condition(condition)
  34586. {
  34587. this._condition = condition;
  34588. },
  34589.  
  34590. get condition()
  34591. {
  34592. return this._condition;
  34593. },
  34594.  
  34595. getLexCondition: function()
  34596. {
  34597. return this.condition.lexCondition;
  34598. },
  34599.  
  34600. setLexCondition: function(lexCondition)
  34601. {
  34602. this.condition.lexCondition = lexCondition;
  34603. },
  34604.  
  34605. _charAt: function(cursor)
  34606. {
  34607. return cursor < this._line.length ? this._line.charAt(cursor) : "\n";
  34608. },
  34609.  
  34610. createInitialCondition: function()
  34611. {
  34612. },
  34613.  
  34614. nextToken: function(cursor)
  34615. {
  34616. }
  34617. }
  34618.  
  34619.  
  34620. WebInspector.SourceTokenizer.Registry = function() {
  34621. this._tokenizers = {};
  34622. this._tokenizerConstructors = {
  34623. "text/css": "SourceCSSTokenizer",
  34624. "text/html": "SourceHTMLTokenizer",
  34625. "text/javascript": "SourceJavaScriptTokenizer",
  34626. "text/x-scss": "SourceCSSTokenizer"
  34627. };
  34628. }
  34629.  
  34630. WebInspector.SourceTokenizer.Registry.getInstance = function()
  34631. {
  34632. if (!WebInspector.SourceTokenizer.Registry._instance)
  34633. WebInspector.SourceTokenizer.Registry._instance = new WebInspector.SourceTokenizer.Registry();
  34634. return WebInspector.SourceTokenizer.Registry._instance;
  34635. }
  34636.  
  34637. WebInspector.SourceTokenizer.Registry.prototype = {
  34638. getTokenizer: function(mimeType)
  34639. {
  34640. if (!this._tokenizerConstructors[mimeType])
  34641. return null;
  34642. var tokenizerClass = this._tokenizerConstructors[mimeType];
  34643. var tokenizer = this._tokenizers[tokenizerClass];
  34644. if (!tokenizer) {
  34645. tokenizer = new WebInspector[tokenizerClass]();
  34646. this._tokenizers[tokenizerClass] = tokenizer;
  34647. }
  34648. return tokenizer;
  34649. }
  34650. }
  34651.  
  34652.  
  34653.  
  34654.  
  34655.  
  34656.  
  34657.  
  34658.  
  34659.  
  34660.  
  34661.  
  34662. WebInspector.SourceCSSTokenizer = function()
  34663. {
  34664. WebInspector.SourceTokenizer.call(this);
  34665.  
  34666. this._propertyKeywords = WebInspector.CSSCompletions.cssPropertiesMetainfoKeySet();
  34667. this._colorKeywords = WebInspector.CSSKeywordCompletions.colors();
  34668.  
  34669. this._valueKeywords = [
  34670. "above", "absolute", "activeborder", "activecaption", "afar", "after-white-space", "ahead", "alias", "all", "all-scroll",
  34671. "alternate", "always", "amharic", "amharic-abegede", "antialiased", "appworkspace", "arabic-indic", "armenian", "asterisks",
  34672. "auto", "avoid", "background", "backwards", "baseline", "below", "bidi-override", "binary", "bengali", "blink",
  34673. "block", "block-axis", "bold", "bolder", "border", "border-box", "both", "bottom", "break-all", "break-word", "button",
  34674. "button-bevel", "buttonface", "buttonhighlight", "buttonshadow", "buttontext", "cambodian", "capitalize", "caps-lock-indicator",
  34675. "caption", "captiontext", "caret", "cell", "center", "checkbox", "circle", "cjk-earthly-branch", "cjk-heavenly-stem", "cjk-ideographic",
  34676. "clear", "clip", "close-quote", "col-resize", "collapse", "compact", "condensed", "contain", "content", "content-box", "context-menu",
  34677. "continuous", "copy", "cover", "crop", "cross", "crosshair", "currentcolor", "cursive", "dashed", "decimal", "decimal-leading-zero", "default",
  34678. "default-button", "destination-atop", "destination-in", "destination-out", "destination-over", "devanagari", "disc", "discard", "document",
  34679. "dot-dash", "dot-dot-dash", "dotted", "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out", "element",
  34680. "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede", "ethiopic-abegede-am-et", "ethiopic-abegede-gez",
  34681. "ethiopic-abegede-ti-er", "ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er", "ethiopic-halehame-aa-et",
  34682. "ethiopic-halehame-am-et", "ethiopic-halehame-gez", "ethiopic-halehame-om-et", "ethiopic-halehame-sid-et",
  34683. "ethiopic-halehame-so-et", "ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", "ethiopic-halehame-tig", "ew-resize", "expanded",
  34684. "extra-condensed", "extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "footnotes", "forwards", "from", "geometricPrecision",
  34685. "georgian", "graytext", "groove", "gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hebrew", "help",
  34686. "hidden", "hide", "higher", "highlight", "highlighttext", "hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "icon", "ignore",
  34687. "inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite", "infobackground", "infotext", "inherit", "initial", "inline",
  34688. "inline-axis", "inline-block", "inline-table", "inset", "inside", "intrinsic", "invert", "italic", "justify", "kannada", "katakana",
  34689. "katakana-iroha", "khmer", "landscape", "lao", "large", "larger", "left", "level", "lighter", "line-through", "linear", "lines",
  34690. "list-item", "listbox", "listitem", "local", "logical", "loud", "lower", "lower-alpha", "lower-armenian", "lower-greek",
  34691. "lower-hexadecimal", "lower-latin", "lower-norwegian", "lower-roman", "lowercase", "ltr", "malayalam", "match", "media-controls-background",
  34692. "media-current-time-display", "media-fullscreen-button", "media-mute-button", "media-play-button", "media-return-to-realtime-button",
  34693. "media-rewind-button", "media-seek-back-button", "media-seek-forward-button", "media-slider", "media-sliderthumb", "media-time-remaining-display",
  34694. "media-volume-slider", "media-volume-slider-container", "media-volume-sliderthumb", "medium", "menu", "menulist", "menulist-button",
  34695. "menulist-text", "menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic", "mix", "mongolian", "monospace", "move", "multiple",
  34696. "myanmar", "n-resize", "narrower", "navy", "ne-resize", "nesw-resize", "no-close-quote", "no-drop", "no-open-quote", "no-repeat", "none",
  34697. "normal", "not-allowed", "nowrap", "ns-resize", "nw-resize", "nwse-resize", "oblique", "octal", "open-quote", "optimizeLegibility",
  34698. "optimizeSpeed", "oriya", "oromo", "outset", "outside", "overlay", "overline", "padding", "padding-box", "painted", "paused",
  34699. "persian", "plus-darker", "plus-lighter", "pointer", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d", "progress",
  34700. "push-button", "radio", "read-only", "read-write", "read-write-plaintext-only", "relative", "repeat", "repeat-x",
  34701. "repeat-y", "reset", "reverse", "rgb", "rgba", "ridge", "right", "round", "row-resize", "rtl", "run-in", "running", "s-resize", "sans-serif",
  34702. "scroll", "scrollbar", "se-resize", "searchfield", "searchfield-cancel-button", "searchfield-decoration", "searchfield-results-button",
  34703. "searchfield-results-decoration", "semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama", "single",
  34704. "skip-white-space", "slide", "slider-horizontal", "slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
  34705. "small", "small-caps", "small-caption", "smaller", "solid", "somali", "source-atop", "source-in", "source-out", "source-over",
  34706. "space", "square", "square-button", "start", "static", "status-bar", "stretch", "stroke", "sub", "subpixel-antialiased", "super",
  34707. "sw-resize", "table", "table-caption", "table-cell", "table-column", "table-column-group", "table-footer-group", "table-header-group",
  34708. "table-row", "table-row-group", "telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai", "thick", "thin",
  34709. "threeddarkshadow", "threedface", "threedhighlight", "threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er", "tigrinya-er-abegede",
  34710. "tigrinya-et", "tigrinya-et-abegede", "to", "top", "transparent", "ultra-condensed", "ultra-expanded", "underline", "up", "upper-alpha", "upper-armenian",
  34711. "upper-greek", "upper-hexadecimal", "upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url", "vertical", "vertical-text", "visible",
  34712. "visibleFill", "visiblePainted", "visibleStroke", "visual", "w-resize", "wait", "wave", "white", "wider", "window", "windowframe", "windowtext",
  34713. "x-large", "x-small", "xor", "xx-large", "xx-small", "yellow", "-wap-marquee", "-webkit-activelink", "-webkit-auto", "-webkit-baseline-middle",
  34714. "-webkit-body", "-webkit-box", "-webkit-center", "-webkit-control", "-webkit-focus-ring-color", "-webkit-grab", "-webkit-grabbing",
  34715. "-webkit-gradient", "-webkit-inline-box", "-webkit-left", "-webkit-link", "-webkit-marquee", "-webkit-mini-control", "-webkit-nowrap", "-webkit-pictograph",
  34716. "-webkit-right", "-webkit-small-control", "-webkit-text", "-webkit-xxx-large", "-webkit-zoom-in", "-webkit-zoom-out",
  34717. ].keySet();
  34718.  
  34719. this._scssValueKeywords = [
  34720. "abs", "adjust-color", "adjust-hue", "alpha", "append", "ceil", "change-color", "comparable", "complement", "darken", "desaturate",
  34721. "fade-in", "fade-out", "floor", "grayscale", "hue", "ie-hex-str", "invert", "join", "length", "lighten",
  34722. "lightness", "max", "min", "mix", "nth", "opacify", "opacity", "percentage", "quote", "round", "saturate",
  34723. "saturation", "scale-color", "transparentize", "type-of", "unit", "unitless", "unquote", "zip"
  34724. ].keySet();
  34725.  
  34726. this._lexConditions = {
  34727. INITIAL: 0,
  34728. COMMENT: 1,
  34729. DSTRING: 2,
  34730. SSTRING: 3
  34731. };
  34732.  
  34733. this._parseConditions = {
  34734. INITIAL: 0,
  34735. PROPERTY: 1,
  34736. PROPERTY_VALUE: 2,
  34737. AT_RULE: 3,
  34738. AT_MEDIA_RULE: 4
  34739. };
  34740.  
  34741. this.case_INITIAL = 1000;
  34742. this.case_COMMENT = 1002;
  34743. this.case_DSTRING = 1003;
  34744. this.case_SSTRING = 1004;
  34745.  
  34746. this.condition = this.createInitialCondition();
  34747. }
  34748.  
  34749. WebInspector.SourceCSSTokenizer.SCSSAtRelatedKeywords = ["from", "if", "in", "through"].keySet();
  34750.  
  34751. WebInspector.SourceCSSTokenizer.MediaTypes = ["all", "aural", "braille", "embossed", "handheld", "import", "print", "projection", "screen", "tty", "tv"].keySet();
  34752.  
  34753. WebInspector.SourceCSSTokenizer.prototype = {
  34754. createInitialCondition: function()
  34755. {
  34756. return { lexCondition: this._lexConditions.INITIAL, parseCondition: this._parseConditions.INITIAL };
  34757. },
  34758.  
  34759.  
  34760. _stringToken: function(cursor, stringEnds)
  34761. {
  34762. if (this._isPropertyValue())
  34763. this.tokenType = "css-string";
  34764. else
  34765. this.tokenType = null;
  34766. return cursor;
  34767. },
  34768.  
  34769. _isPropertyValue: function()
  34770. {
  34771. return this._condition.parseCondition === this._parseConditions.PROPERTY_VALUE || this._condition.parseCondition === this._parseConditions.AT_RULE;
  34772. },
  34773.  
  34774. _setParseCondition: function(condition)
  34775. {
  34776. this._condition.parseCondition = condition;
  34777. },
  34778.  
  34779. nextToken: function(cursor)
  34780. {
  34781. var cursorOnEnter = cursor;
  34782. var gotoCase = 1;
  34783. var YYMARKER;
  34784. while (1) {
  34785. switch (gotoCase)
  34786.  
  34787.  
  34788. {
  34789. case 1: var yych;
  34790. var yyaccept = 0;
  34791. if (this.getLexCondition() < 2) {
  34792. if (this.getLexCondition() < 1) {
  34793. { gotoCase = this.case_INITIAL; continue; };
  34794. } else {
  34795. { gotoCase = this.case_COMMENT; continue; };
  34796. }
  34797. } else {
  34798. if (this.getLexCondition() < 3) {
  34799. { gotoCase = this.case_DSTRING; continue; };
  34800. } else {
  34801. { gotoCase = this.case_SSTRING; continue; };
  34802. }
  34803. }
  34804.  
  34805. case this.case_COMMENT:
  34806.  
  34807. yych = this._charAt(cursor);
  34808. if (yych <= '\f') {
  34809. if (yych == '\n') { gotoCase = 4; continue; };
  34810. { gotoCase = 3; continue; };
  34811. } else {
  34812. if (yych <= '\r') { gotoCase = 4; continue; };
  34813. if (yych == '*') { gotoCase = 6; continue; };
  34814. { gotoCase = 3; continue; };
  34815. }
  34816. case 2:
  34817. { this.tokenType = "css-comment"; return cursor; }
  34818. case 3:
  34819. yyaccept = 0;
  34820. yych = this._charAt(YYMARKER = ++cursor);
  34821. { gotoCase = 12; continue; };
  34822. case 4:
  34823. ++cursor;
  34824. { this.tokenType = null; return cursor; }
  34825. case 6:
  34826. yyaccept = 1;
  34827. yych = this._charAt(YYMARKER = ++cursor);
  34828. if (yych == '*') { gotoCase = 9; continue; };
  34829. if (yych != '/') { gotoCase = 11; continue; };
  34830. case 7:
  34831. ++cursor;
  34832. this.setLexCondition(this._lexConditions.INITIAL);
  34833. { this.tokenType = "css-comment"; return cursor; }
  34834. case 9:
  34835. ++cursor;
  34836. yych = this._charAt(cursor);
  34837. if (yych == '*') { gotoCase = 9; continue; };
  34838. if (yych == '/') { gotoCase = 7; continue; };
  34839. case 11:
  34840. yyaccept = 0;
  34841. YYMARKER = ++cursor;
  34842. yych = this._charAt(cursor);
  34843. case 12:
  34844. if (yych <= '\f') {
  34845. if (yych == '\n') { gotoCase = 2; continue; };
  34846. { gotoCase = 11; continue; };
  34847. } else {
  34848. if (yych <= '\r') { gotoCase = 2; continue; };
  34849. if (yych == '*') { gotoCase = 9; continue; };
  34850. { gotoCase = 11; continue; };
  34851. }
  34852.  
  34853. case this.case_DSTRING:
  34854. yych = this._charAt(cursor);
  34855. if (yych <= '\r') {
  34856. if (yych == '\n') { gotoCase = 17; continue; };
  34857. if (yych <= '\f') { gotoCase = 16; continue; };
  34858. { gotoCase = 17; continue; };
  34859. } else {
  34860. if (yych <= '"') {
  34861. if (yych <= '!') { gotoCase = 16; continue; };
  34862. { gotoCase = 19; continue; };
  34863. } else {
  34864. if (yych == '\\') { gotoCase = 21; continue; };
  34865. { gotoCase = 16; continue; };
  34866. }
  34867. }
  34868. case 15:
  34869. { return this._stringToken(cursor); }
  34870. case 16:
  34871. yyaccept = 0;
  34872. yych = this._charAt(YYMARKER = ++cursor);
  34873. { gotoCase = 23; continue; };
  34874. case 17:
  34875. ++cursor;
  34876. case 18:
  34877. { this.tokenType = null; return cursor; }
  34878. case 19:
  34879. ++cursor;
  34880. case 20:
  34881. this.setLexCondition(this._lexConditions.INITIAL);
  34882. { return this._stringToken(cursor, true); }
  34883. case 21:
  34884. yych = this._charAt(++cursor);
  34885. if (yych <= 'e') {
  34886. if (yych <= '\'') {
  34887. if (yych == '"') { gotoCase = 22; continue; };
  34888. if (yych <= '&') { gotoCase = 18; continue; };
  34889. } else {
  34890. if (yych <= '\\') {
  34891. if (yych <= '[') { gotoCase = 18; continue; };
  34892. } else {
  34893. if (yych != 'b') { gotoCase = 18; continue; };
  34894. }
  34895. }
  34896. } else {
  34897. if (yych <= 'r') {
  34898. if (yych <= 'm') {
  34899. if (yych >= 'g') { gotoCase = 18; continue; };
  34900. } else {
  34901. if (yych <= 'n') { gotoCase = 22; continue; };
  34902. if (yych <= 'q') { gotoCase = 18; continue; };
  34903. }
  34904. } else {
  34905. if (yych <= 't') {
  34906. if (yych <= 's') { gotoCase = 18; continue; };
  34907. } else {
  34908. if (yych != 'v') { gotoCase = 18; continue; };
  34909. }
  34910. }
  34911. }
  34912. case 22:
  34913. yyaccept = 0;
  34914. YYMARKER = ++cursor;
  34915. yych = this._charAt(cursor);
  34916. case 23:
  34917. if (yych <= '\r') {
  34918. if (yych == '\n') { gotoCase = 15; continue; };
  34919. if (yych <= '\f') { gotoCase = 22; continue; };
  34920. { gotoCase = 15; continue; };
  34921. } else {
  34922. if (yych <= '"') {
  34923. if (yych <= '!') { gotoCase = 22; continue; };
  34924. { gotoCase = 26; continue; };
  34925. } else {
  34926. if (yych != '\\') { gotoCase = 22; continue; };
  34927. }
  34928. }
  34929. ++cursor;
  34930. yych = this._charAt(cursor);
  34931. if (yych <= 'e') {
  34932. if (yych <= '\'') {
  34933. if (yych == '"') { gotoCase = 22; continue; };
  34934. if (yych >= '\'') { gotoCase = 22; continue; };
  34935. } else {
  34936. if (yych <= '\\') {
  34937. if (yych >= '\\') { gotoCase = 22; continue; };
  34938. } else {
  34939. if (yych == 'b') { gotoCase = 22; continue; };
  34940. }
  34941. }
  34942. } else {
  34943. if (yych <= 'r') {
  34944. if (yych <= 'm') {
  34945. if (yych <= 'f') { gotoCase = 22; continue; };
  34946. } else {
  34947. if (yych <= 'n') { gotoCase = 22; continue; };
  34948. if (yych >= 'r') { gotoCase = 22; continue; };
  34949. }
  34950. } else {
  34951. if (yych <= 't') {
  34952. if (yych >= 't') { gotoCase = 22; continue; };
  34953. } else {
  34954. if (yych == 'v') { gotoCase = 22; continue; };
  34955. }
  34956. }
  34957. }
  34958. cursor = YYMARKER;
  34959. { gotoCase = 15; continue; };
  34960. case 26:
  34961. ++cursor;
  34962. yych = this._charAt(cursor);
  34963. { gotoCase = 20; continue; };
  34964.  
  34965. case this.case_INITIAL:
  34966. yych = this._charAt(cursor);
  34967. if (yych <= ':') {
  34968. if (yych <= '&') {
  34969. if (yych <= '"') {
  34970. if (yych <= ' ') { gotoCase = 29; continue; };
  34971. if (yych <= '!') { gotoCase = 31; continue; };
  34972. { gotoCase = 33; continue; };
  34973. } else {
  34974. if (yych <= '#') { gotoCase = 34; continue; };
  34975. if (yych <= '$') { gotoCase = 35; continue; };
  34976. if (yych >= '&') { gotoCase = 31; continue; };
  34977. }
  34978. } else {
  34979. if (yych <= '-') {
  34980. if (yych <= '\'') { gotoCase = 36; continue; };
  34981. if (yych >= '-') { gotoCase = 37; continue; };
  34982. } else {
  34983. if (yych <= '.') { gotoCase = 38; continue; };
  34984. if (yych <= '/') { gotoCase = 39; continue; };
  34985. if (yych <= '9') { gotoCase = 40; continue; };
  34986. { gotoCase = 42; continue; };
  34987. }
  34988. }
  34989. } else {
  34990. if (yych <= ']') {
  34991. if (yych <= '=') {
  34992. if (yych <= ';') { gotoCase = 44; continue; };
  34993. if (yych >= '=') { gotoCase = 31; continue; };
  34994. } else {
  34995. if (yych <= '?') { gotoCase = 29; continue; };
  34996. if (yych != '\\') { gotoCase = 31; continue; };
  34997. }
  34998. } else {
  34999. if (yych <= 'z') {
  35000. if (yych == '_') { gotoCase = 31; continue; };
  35001. if (yych >= 'a') { gotoCase = 31; continue; };
  35002. } else {
  35003. if (yych <= '{') { gotoCase = 46; continue; };
  35004. if (yych == '}') { gotoCase = 48; continue; };
  35005. }
  35006. }
  35007. }
  35008. case 29:
  35009. ++cursor;
  35010. case 30:
  35011. { this.tokenType = null; return cursor; }
  35012. case 31:
  35013. ++cursor;
  35014. yych = this._charAt(cursor);
  35015. { gotoCase = 51; continue; };
  35016. case 32:
  35017. {
  35018. var token = this._line.substring(cursorOnEnter, cursor);
  35019. this.tokenType = null;
  35020. if (this._condition.parseCondition === this._parseConditions.INITIAL || this._condition.parseCondition === this._parseConditions.PROPERTY) {
  35021. if (token.charAt(0) === "@") {
  35022. this.tokenType = "css-at-rule";
  35023. this._setParseCondition(token === "@media" ? this._parseConditions.AT_MEDIA_RULE : this._parseConditions.AT_RULE);
  35024. this._condition.atKeyword = token;
  35025. } else if (this._condition.parseCondition === this._parseConditions.INITIAL)
  35026. this.tokenType = "css-selector";
  35027. else if (this._propertyKeywords.hasOwnProperty(token))
  35028. this.tokenType = "css-property";
  35029. } else if (this._condition.parseCondition === this._parseConditions.AT_MEDIA_RULE || this._condition.parseCondition === this._parseConditions.AT_RULE) {
  35030. if (WebInspector.SourceCSSTokenizer.SCSSAtRelatedKeywords.hasOwnProperty(token))
  35031. this.tokenType = "css-at-rule";
  35032. else if (WebInspector.SourceCSSTokenizer.MediaTypes.hasOwnProperty(token))
  35033. this.tokenType = "css-keyword";
  35034. }
  35035. if (this.tokenType)
  35036. return cursor;
  35037.  
  35038. if (this._isPropertyValue()) {
  35039. var firstChar = token.charAt(0);
  35040. if (firstChar === "$")
  35041. this.tokenType = "scss-variable";
  35042. else if (firstChar === "!")
  35043. this.tokenType = "css-bang-keyword";
  35044. else if (this._condition.atKeyword === "@extend")
  35045. this.tokenType = "css-selector";
  35046. else if (this._valueKeywords.hasOwnProperty(token) || this._scssValueKeywords.hasOwnProperty(token))
  35047. this.tokenType = "css-keyword";
  35048. else if (this._colorKeywords.hasOwnProperty(token)) {
  35049.  
  35050. this.tokenType = "css-color";
  35051. }
  35052. } else if (this._condition.parseCondition !== this._parseConditions.PROPERTY_VALUE)
  35053. this.tokenType = "css-selector";
  35054. return cursor;
  35055. }
  35056. case 33:
  35057. yyaccept = 0;
  35058. yych = this._charAt(YYMARKER = ++cursor);
  35059. if (yych <= '.') {
  35060. if (yych <= '!') {
  35061. if (yych <= '\f') {
  35062. if (yych == '\n') { gotoCase = 32; continue; };
  35063. { gotoCase = 132; continue; };
  35064. } else {
  35065. if (yych <= '\r') { gotoCase = 32; continue; };
  35066. if (yych <= ' ') { gotoCase = 132; continue; };
  35067. { gotoCase = 130; continue; };
  35068. }
  35069. } else {
  35070. if (yych <= '\'') {
  35071. if (yych <= '"') { gotoCase = 116; continue; };
  35072. if (yych <= '%') { gotoCase = 132; continue; };
  35073. { gotoCase = 130; continue; };
  35074. } else {
  35075. if (yych == '-') { gotoCase = 130; continue; };
  35076. { gotoCase = 132; continue; };
  35077. }
  35078. }
  35079. } else {
  35080. if (yych <= '\\') {
  35081. if (yych <= '=') {
  35082. if (yych <= '9') { gotoCase = 130; continue; };
  35083. if (yych <= '<') { gotoCase = 132; continue; };
  35084. { gotoCase = 130; continue; };
  35085. } else {
  35086. if (yych <= '?') { gotoCase = 132; continue; };
  35087. if (yych <= '[') { gotoCase = 130; continue; };
  35088. { gotoCase = 134; continue; };
  35089. }
  35090. } else {
  35091. if (yych <= '_') {
  35092. if (yych == '^') { gotoCase = 132; continue; };
  35093. { gotoCase = 130; continue; };
  35094. } else {
  35095. if (yych <= '`') { gotoCase = 132; continue; };
  35096. if (yych <= 'z') { gotoCase = 130; continue; };
  35097. { gotoCase = 132; continue; };
  35098. }
  35099. }
  35100. }
  35101. case 34:
  35102. yych = this._charAt(++cursor);
  35103. if (yych <= '@') {
  35104. if (yych <= '/') { gotoCase = 30; continue; };
  35105. if (yych <= '9') { gotoCase = 127; continue; };
  35106. { gotoCase = 30; continue; };
  35107. } else {
  35108. if (yych <= 'Z') { gotoCase = 127; continue; };
  35109. if (yych <= '`') { gotoCase = 30; continue; };
  35110. if (yych <= 'z') { gotoCase = 127; continue; };
  35111. { gotoCase = 30; continue; };
  35112. }
  35113. case 35:
  35114. yych = this._charAt(++cursor);
  35115. if (yych <= '<') {
  35116. if (yych <= '\'') {
  35117. if (yych <= ' ') { gotoCase = 30; continue; };
  35118. if (yych <= '"') { gotoCase = 124; continue; };
  35119. if (yych <= '%') { gotoCase = 30; continue; };
  35120. { gotoCase = 124; continue; };
  35121. } else {
  35122. if (yych <= '-') {
  35123. if (yych <= ',') { gotoCase = 30; continue; };
  35124. { gotoCase = 124; continue; };
  35125. } else {
  35126. if (yych <= '.') { gotoCase = 30; continue; };
  35127. if (yych <= '9') { gotoCase = 124; continue; };
  35128. { gotoCase = 30; continue; };
  35129. }
  35130. }
  35131. } else {
  35132. if (yych <= ']') {
  35133. if (yych <= '?') {
  35134. if (yych <= '=') { gotoCase = 124; continue; };
  35135. { gotoCase = 30; continue; };
  35136. } else {
  35137. if (yych == '\\') { gotoCase = 30; continue; };
  35138. { gotoCase = 124; continue; };
  35139. }
  35140. } else {
  35141. if (yych <= '_') {
  35142. if (yych <= '^') { gotoCase = 30; continue; };
  35143. { gotoCase = 124; continue; };
  35144. } else {
  35145. if (yych <= '`') { gotoCase = 30; continue; };
  35146. if (yych <= 'z') { gotoCase = 124; continue; };
  35147. { gotoCase = 30; continue; };
  35148. }
  35149. }
  35150. }
  35151. case 36:
  35152. yyaccept = 0;
  35153. yych = this._charAt(YYMARKER = ++cursor);
  35154. if (yych <= '.') {
  35155. if (yych <= '"') {
  35156. if (yych <= '\f') {
  35157. if (yych == '\n') { gotoCase = 32; continue; };
  35158. { gotoCase = 118; continue; };
  35159. } else {
  35160. if (yych <= '\r') { gotoCase = 32; continue; };
  35161. if (yych <= ' ') { gotoCase = 118; continue; };
  35162. { gotoCase = 114; continue; };
  35163. }
  35164. } else {
  35165. if (yych <= '\'') {
  35166. if (yych <= '%') { gotoCase = 118; continue; };
  35167. if (yych <= '&') { gotoCase = 114; continue; };
  35168. { gotoCase = 116; continue; };
  35169. } else {
  35170. if (yych == '-') { gotoCase = 114; continue; };
  35171. { gotoCase = 118; continue; };
  35172. }
  35173. }
  35174. } else {
  35175. if (yych <= '\\') {
  35176. if (yych <= '=') {
  35177. if (yych <= '9') { gotoCase = 114; continue; };
  35178. if (yych <= '<') { gotoCase = 118; continue; };
  35179. { gotoCase = 114; continue; };
  35180. } else {
  35181. if (yych <= '?') { gotoCase = 118; continue; };
  35182. if (yych <= '[') { gotoCase = 114; continue; };
  35183. { gotoCase = 120; continue; };
  35184. }
  35185. } else {
  35186. if (yych <= '_') {
  35187. if (yych == '^') { gotoCase = 118; continue; };
  35188. { gotoCase = 114; continue; };
  35189. } else {
  35190. if (yych <= '`') { gotoCase = 118; continue; };
  35191. if (yych <= 'z') { gotoCase = 114; continue; };
  35192. { gotoCase = 118; continue; };
  35193. }
  35194. }
  35195. }
  35196. case 37:
  35197. yyaccept = 0;
  35198. yych = this._charAt(YYMARKER = ++cursor);
  35199. if (yych == '.') { gotoCase = 67; continue; };
  35200. if (yych <= '/') { gotoCase = 51; continue; };
  35201. if (yych <= '9') { gotoCase = 52; continue; };
  35202. { gotoCase = 51; continue; };
  35203. case 38:
  35204. yych = this._charAt(++cursor);
  35205. if (yych <= '/') { gotoCase = 30; continue; };
  35206. if (yych <= '9') { gotoCase = 70; continue; };
  35207. { gotoCase = 30; continue; };
  35208. case 39:
  35209. yyaccept = 0;
  35210. yych = this._charAt(YYMARKER = ++cursor);
  35211. if (yych == '*') { gotoCase = 106; continue; };
  35212. { gotoCase = 51; continue; };
  35213. case 40:
  35214. yyaccept = 1;
  35215. yych = this._charAt(YYMARKER = ++cursor);
  35216. switch (yych) {
  35217. case '!':
  35218. case '"':
  35219. case '&':
  35220. case '\'':
  35221. case '-':
  35222. case '/':
  35223. case '=':
  35224. case '@':
  35225. case 'A':
  35226. case 'B':
  35227. case 'C':
  35228. case 'D':
  35229. case 'E':
  35230. case 'F':
  35231. case 'G':
  35232. case 'I':
  35233. case 'J':
  35234. case 'K':
  35235. case 'L':
  35236. case 'M':
  35237. case 'N':
  35238. case 'O':
  35239. case 'P':
  35240. case 'Q':
  35241. case 'R':
  35242. case 'S':
  35243. case 'T':
  35244. case 'U':
  35245. case 'V':
  35246. case 'W':
  35247. case 'X':
  35248. case 'Y':
  35249. case 'Z':
  35250. case '[':
  35251. case ']':
  35252. case 'a':
  35253. case 'b':
  35254. case 'f':
  35255. case 'h':
  35256. case 'j':
  35257. case 'l':
  35258. case 'n':
  35259. case 'o':
  35260. case 'q':
  35261. case 'u':
  35262. case 'v':
  35263. case 'w':
  35264. case 'x':
  35265. case 'y':
  35266. case 'z':    { gotoCase = 50; continue; };
  35267. case '%':    { gotoCase = 69; continue; };
  35268. case '.':    { gotoCase = 67; continue; };
  35269. case '0':
  35270. case '1':
  35271. case '2':
  35272. case '3':
  35273. case '4':
  35274. case '5':
  35275. case '6':
  35276. case '7':
  35277. case '8':
  35278. case '9':    { gotoCase = 52; continue; };
  35279. case 'H':    { gotoCase = 54; continue; };
  35280. case '_':    { gotoCase = 55; continue; };
  35281. case 'c':    { gotoCase = 56; continue; };
  35282. case 'd':    { gotoCase = 57; continue; };
  35283. case 'e':    { gotoCase = 58; continue; };
  35284. case 'g':    { gotoCase = 59; continue; };
  35285. case 'i':    { gotoCase = 60; continue; };
  35286. case 'k':    { gotoCase = 61; continue; };
  35287. case 'm':    { gotoCase = 62; continue; };
  35288. case 'p':    { gotoCase = 63; continue; };
  35289. case 'r':    { gotoCase = 64; continue; };
  35290. case 's':    { gotoCase = 65; continue; };
  35291. case 't':    { gotoCase = 66; continue; };
  35292. default:    { gotoCase = 41; continue; };
  35293. }
  35294. case 41:
  35295. {
  35296. if (this._isPropertyValue())
  35297. this.tokenType = "css-number";
  35298. else
  35299. this.tokenType = null;
  35300. return cursor;
  35301. }
  35302. case 42:
  35303. ++cursor;
  35304. {
  35305. this.tokenType = null;
  35306. if (this._condition.parseCondition === this._parseConditions.PROPERTY || this._condition.parseCondition === this._parseConditions.INITIAL)
  35307. this._setParseCondition(this._parseConditions.PROPERTY_VALUE);
  35308. return cursor;
  35309. }
  35310. case 44:
  35311. ++cursor;
  35312. {
  35313. this.tokenType = null;
  35314. this._setParseCondition(this._condition.openBraces ? this._parseConditions.PROPERTY : this._parseConditions.INITIAL);
  35315. delete this._condition.atKeyword;
  35316. return cursor;
  35317. }
  35318. case 46:
  35319. ++cursor;
  35320. {
  35321. this.tokenType = "block-start";
  35322. this._condition.openBraces = (this._condition.openBraces || 0) + 1;
  35323. if (this._condition.parseCondition === this._parseConditions.AT_MEDIA_RULE)
  35324. this._setParseCondition(this._parseConditions.INITIAL);
  35325. else
  35326. this._setParseCondition(this._parseConditions.PROPERTY);
  35327. return cursor;
  35328. }
  35329. case 48:
  35330. ++cursor;
  35331. {
  35332. this.tokenType = "block-end";
  35333. if (this._condition.openBraces > 0)
  35334. --this._condition.openBraces;
  35335. this._setParseCondition(this._condition.openBraces ? this._parseConditions.PROPERTY : this._parseConditions.INITIAL);
  35336. delete this._condition.atKeyword;
  35337. return cursor;
  35338. }
  35339. case 50:
  35340. ++cursor;
  35341. yych = this._charAt(cursor);
  35342. case 51:
  35343. if (yych <= '<') {
  35344. if (yych <= '\'') {
  35345. if (yych <= ' ') { gotoCase = 32; continue; };
  35346. if (yych <= '"') { gotoCase = 50; continue; };
  35347. if (yych <= '%') { gotoCase = 32; continue; };
  35348. { gotoCase = 50; continue; };
  35349. } else {
  35350. if (yych <= '-') {
  35351. if (yych <= ',') { gotoCase = 32; continue; };
  35352. { gotoCase = 50; continue; };
  35353. } else {
  35354. if (yych <= '.') { gotoCase = 32; continue; };
  35355. if (yych <= '9') { gotoCase = 50; continue; };
  35356. { gotoCase = 32; continue; };
  35357. }
  35358. }
  35359. } else {
  35360. if (yych <= ']') {
  35361. if (yych <= '?') {
  35362. if (yych <= '=') { gotoCase = 50; continue; };
  35363. { gotoCase = 32; continue; };
  35364. } else {
  35365. if (yych == '\\') { gotoCase = 32; continue; };
  35366. { gotoCase = 50; continue; };
  35367. }
  35368. } else {
  35369. if (yych <= '_') {
  35370. if (yych <= '^') { gotoCase = 32; continue; };
  35371. { gotoCase = 50; continue; };
  35372. } else {
  35373. if (yych <= '`') { gotoCase = 32; continue; };
  35374. if (yych <= 'z') { gotoCase = 50; continue; };
  35375. { gotoCase = 32; continue; };
  35376. }
  35377. }
  35378. }
  35379. case 52:
  35380. yyaccept = 1;
  35381. YYMARKER = ++cursor;
  35382. yych = this._charAt(cursor);
  35383. switch (yych) {
  35384. case '!':
  35385. case '"':
  35386. case '&':
  35387. case '\'':
  35388. case '-':
  35389. case '/':
  35390. case '=':
  35391. case '@':
  35392. case 'A':
  35393. case 'B':
  35394. case 'C':
  35395. case 'D':
  35396. case 'E':
  35397. case 'F':
  35398. case 'G':
  35399. case 'I':
  35400. case 'J':
  35401. case 'K':
  35402. case 'L':
  35403. case 'M':
  35404. case 'N':
  35405. case 'O':
  35406. case 'P':
  35407. case 'Q':
  35408. case 'R':
  35409. case 'S':
  35410. case 'T':
  35411. case 'U':
  35412. case 'V':
  35413. case 'W':
  35414. case 'X':
  35415. case 'Y':
  35416. case 'Z':
  35417. case '[':
  35418. case ']':
  35419. case 'a':
  35420. case 'b':
  35421. case 'f':
  35422. case 'h':
  35423. case 'j':
  35424. case 'l':
  35425. case 'n':
  35426. case 'o':
  35427. case 'q':
  35428. case 'u':
  35429. case 'v':
  35430. case 'w':
  35431. case 'x':
  35432. case 'y':
  35433. case 'z':    { gotoCase = 50; continue; };
  35434. case '%':    { gotoCase = 69; continue; };
  35435. case '.':    { gotoCase = 67; continue; };
  35436. case '0':
  35437. case '1':
  35438. case '2':
  35439. case '3':
  35440. case '4':
  35441. case '5':
  35442. case '6':
  35443. case '7':
  35444. case '8':
  35445. case '9':    { gotoCase = 52; continue; };
  35446. case 'H':    { gotoCase = 54; continue; };
  35447. case '_':    { gotoCase = 55; continue; };
  35448. case 'c':    { gotoCase = 56; continue; };
  35449. case 'd':    { gotoCase = 57; continue; };
  35450. case 'e':    { gotoCase = 58; continue; };
  35451. case 'g':    { gotoCase = 59; continue; };
  35452. case 'i':    { gotoCase = 60; continue; };
  35453. case 'k':    { gotoCase = 61; continue; };
  35454. case 'm':    { gotoCase = 62; continue; };
  35455. case 'p':    { gotoCase = 63; continue; };
  35456. case 'r':    { gotoCase = 64; continue; };
  35457. case 's':    { gotoCase = 65; continue; };
  35458. case 't':    { gotoCase = 66; continue; };
  35459. default:    { gotoCase = 41; continue; };
  35460. }
  35461. case 54:
  35462. yych = this._charAt(++cursor);
  35463. if (yych == 'z') { gotoCase = 65; continue; };
  35464. { gotoCase = 51; continue; };
  35465. case 55:
  35466. yych = this._charAt(++cursor);
  35467. if (yych == '_') { gotoCase = 103; continue; };
  35468. { gotoCase = 51; continue; };
  35469. case 56:
  35470. yych = this._charAt(++cursor);
  35471. if (yych == 'm') { gotoCase = 65; continue; };
  35472. { gotoCase = 51; continue; };
  35473. case 57:
  35474. yych = this._charAt(++cursor);
  35475. if (yych == 'e') { gotoCase = 102; continue; };
  35476. { gotoCase = 51; continue; };
  35477. case 58:
  35478. yych = this._charAt(++cursor);
  35479. if (yych == 'm') { gotoCase = 65; continue; };
  35480. if (yych == 'x') { gotoCase = 65; continue; };
  35481. { gotoCase = 51; continue; };
  35482. case 59:
  35483. yych = this._charAt(++cursor);
  35484. if (yych == 'r') { gotoCase = 100; continue; };
  35485. { gotoCase = 51; continue; };
  35486. case 60:
  35487. yych = this._charAt(++cursor);
  35488. if (yych == 'n') { gotoCase = 65; continue; };
  35489. { gotoCase = 51; continue; };
  35490. case 61:
  35491. yych = this._charAt(++cursor);
  35492. if (yych == 'H') { gotoCase = 99; continue; };
  35493. { gotoCase = 51; continue; };
  35494. case 62:
  35495. yych = this._charAt(++cursor);
  35496. if (yych == 'm') { gotoCase = 65; continue; };
  35497. if (yych == 's') { gotoCase = 65; continue; };
  35498. { gotoCase = 51; continue; };
  35499. case 63:
  35500. yych = this._charAt(++cursor);
  35501. if (yych <= 's') {
  35502. if (yych == 'c') { gotoCase = 65; continue; };
  35503. { gotoCase = 51; continue; };
  35504. } else {
  35505. if (yych <= 't') { gotoCase = 65; continue; };
  35506. if (yych == 'x') { gotoCase = 65; continue; };
  35507. { gotoCase = 51; continue; };
  35508. }
  35509. case 64:
  35510. yych = this._charAt(++cursor);
  35511. if (yych == 'a') { gotoCase = 97; continue; };
  35512. if (yych == 'e') { gotoCase = 98; continue; };
  35513. { gotoCase = 51; continue; };
  35514. case 65:
  35515. yych = this._charAt(++cursor);
  35516. if (yych <= '<') {
  35517. if (yych <= '\'') {
  35518. if (yych <= ' ') { gotoCase = 41; continue; };
  35519. if (yych <= '"') { gotoCase = 50; continue; };
  35520. if (yych <= '%') { gotoCase = 41; continue; };
  35521. { gotoCase = 50; continue; };
  35522. } else {
  35523. if (yych <= '-') {
  35524. if (yych <= ',') { gotoCase = 41; continue; };
  35525. { gotoCase = 50; continue; };
  35526. } else {
  35527. if (yych <= '.') { gotoCase = 41; continue; };
  35528. if (yych <= '9') { gotoCase = 50; continue; };
  35529. { gotoCase = 41; continue; };
  35530. }
  35531. }
  35532. } else {
  35533. if (yych <= ']') {
  35534. if (yych <= '?') {
  35535. if (yych <= '=') { gotoCase = 50; continue; };
  35536. { gotoCase = 41; continue; };
  35537. } else {
  35538. if (yych == '\\') { gotoCase = 41; continue; };
  35539. { gotoCase = 50; continue; };
  35540. }
  35541. } else {
  35542. if (yych <= '_') {
  35543. if (yych <= '^') { gotoCase = 41; continue; };
  35544. { gotoCase = 50; continue; };
  35545. } else {
  35546. if (yych <= '`') { gotoCase = 41; continue; };
  35547. if (yych <= 'z') { gotoCase = 50; continue; };
  35548. { gotoCase = 41; continue; };
  35549. }
  35550. }
  35551. }
  35552. case 66:
  35553. yych = this._charAt(++cursor);
  35554. if (yych == 'u') { gotoCase = 95; continue; };
  35555. { gotoCase = 51; continue; };
  35556. case 67:
  35557. yych = this._charAt(++cursor);
  35558. if (yych <= '/') { gotoCase = 68; continue; };
  35559. if (yych <= '9') { gotoCase = 70; continue; };
  35560. case 68:
  35561. cursor = YYMARKER;
  35562. if (yyaccept <= 0) {
  35563. { gotoCase = 32; continue; };
  35564. } else {
  35565. { gotoCase = 41; continue; };
  35566. }
  35567. case 69:
  35568. yych = this._charAt(++cursor);
  35569. { gotoCase = 41; continue; };
  35570. case 70:
  35571. yyaccept = 1;
  35572. YYMARKER = ++cursor;
  35573. yych = this._charAt(cursor);
  35574. if (yych <= 'f') {
  35575. if (yych <= 'H') {
  35576. if (yych <= '/') {
  35577. if (yych == '%') { gotoCase = 69; continue; };
  35578. { gotoCase = 41; continue; };
  35579. } else {
  35580. if (yych <= '9') { gotoCase = 70; continue; };
  35581. if (yych <= 'G') { gotoCase = 41; continue; };
  35582. { gotoCase = 82; continue; };
  35583. }
  35584. } else {
  35585. if (yych <= 'b') {
  35586. if (yych == '_') { gotoCase = 74; continue; };
  35587. { gotoCase = 41; continue; };
  35588. } else {
  35589. if (yych <= 'c') { gotoCase = 76; continue; };
  35590. if (yych <= 'd') { gotoCase = 79; continue; };
  35591. if (yych >= 'f') { gotoCase = 41; continue; };
  35592. }
  35593. }
  35594. } else {
  35595. if (yych <= 'm') {
  35596. if (yych <= 'i') {
  35597. if (yych <= 'g') { gotoCase = 80; continue; };
  35598. if (yych <= 'h') { gotoCase = 41; continue; };
  35599. { gotoCase = 78; continue; };
  35600. } else {
  35601. if (yych == 'k') { gotoCase = 83; continue; };
  35602. if (yych <= 'l') { gotoCase = 41; continue; };
  35603. { gotoCase = 77; continue; };
  35604. }
  35605. } else {
  35606. if (yych <= 'q') {
  35607. if (yych == 'p') { gotoCase = 75; continue; };
  35608. { gotoCase = 41; continue; };
  35609. } else {
  35610. if (yych <= 'r') { gotoCase = 73; continue; };
  35611. if (yych <= 's') { gotoCase = 69; continue; };
  35612. if (yych <= 't') { gotoCase = 81; continue; };
  35613. { gotoCase = 41; continue; };
  35614. }
  35615. }
  35616. }
  35617. yych = this._charAt(++cursor);
  35618. if (yych == 'm') { gotoCase = 69; continue; };
  35619. if (yych == 'x') { gotoCase = 69; continue; };
  35620. { gotoCase = 68; continue; };
  35621. case 73:
  35622. yych = this._charAt(++cursor);
  35623. if (yych == 'a') { gotoCase = 93; continue; };
  35624. if (yych == 'e') { gotoCase = 94; continue; };
  35625. { gotoCase = 68; continue; };
  35626. case 74:
  35627. yych = this._charAt(++cursor);
  35628. if (yych == '_') { gotoCase = 90; continue; };
  35629. { gotoCase = 68; continue; };
  35630. case 75:
  35631. yych = this._charAt(++cursor);
  35632. if (yych <= 's') {
  35633. if (yych == 'c') { gotoCase = 69; continue; };
  35634. { gotoCase = 68; continue; };
  35635. } else {
  35636. if (yych <= 't') { gotoCase = 69; continue; };
  35637. if (yych == 'x') { gotoCase = 69; continue; };
  35638. { gotoCase = 68; continue; };
  35639. }
  35640. case 76:
  35641. yych = this._charAt(++cursor);
  35642. if (yych == 'm') { gotoCase = 69; continue; };
  35643. { gotoCase = 68; continue; };
  35644. case 77:
  35645. yych = this._charAt(++cursor);
  35646. if (yych == 'm') { gotoCase = 69; continue; };
  35647. if (yych == 's') { gotoCase = 69; continue; };
  35648. { gotoCase = 68; continue; };
  35649. case 78:
  35650. yych = this._charAt(++cursor);
  35651. if (yych == 'n') { gotoCase = 69; continue; };
  35652. { gotoCase = 68; continue; };
  35653. case 79:
  35654. yych = this._charAt(++cursor);
  35655. if (yych == 'e') { gotoCase = 89; continue; };
  35656. { gotoCase = 68; continue; };
  35657. case 80:
  35658. yych = this._charAt(++cursor);
  35659. if (yych == 'r') { gotoCase = 87; continue; };
  35660. { gotoCase = 68; continue; };
  35661. case 81:
  35662. yych = this._charAt(++cursor);
  35663. if (yych == 'u') { gotoCase = 85; continue; };
  35664. { gotoCase = 68; continue; };
  35665. case 82:
  35666. yych = this._charAt(++cursor);
  35667. if (yych == 'z') { gotoCase = 69; continue; };
  35668. { gotoCase = 68; continue; };
  35669. case 83:
  35670. yych = this._charAt(++cursor);
  35671. if (yych != 'H') { gotoCase = 68; continue; };
  35672. yych = this._charAt(++cursor);
  35673. if (yych == 'z') { gotoCase = 69; continue; };
  35674. { gotoCase = 68; continue; };
  35675. case 85:
  35676. yych = this._charAt(++cursor);
  35677. if (yych != 'r') { gotoCase = 68; continue; };
  35678. yych = this._charAt(++cursor);
  35679. if (yych == 'n') { gotoCase = 69; continue; };
  35680. { gotoCase = 68; continue; };
  35681. case 87:
  35682. yych = this._charAt(++cursor);
  35683. if (yych != 'a') { gotoCase = 68; continue; };
  35684. yych = this._charAt(++cursor);
  35685. if (yych == 'd') { gotoCase = 69; continue; };
  35686. { gotoCase = 68; continue; };
  35687. case 89:
  35688. yych = this._charAt(++cursor);
  35689. if (yych == 'g') { gotoCase = 69; continue; };
  35690. { gotoCase = 68; continue; };
  35691. case 90:
  35692. yych = this._charAt(++cursor);
  35693. if (yych != 'q') { gotoCase = 68; continue; };
  35694. yych = this._charAt(++cursor);
  35695. if (yych != 'e') { gotoCase = 68; continue; };
  35696. yych = this._charAt(++cursor);
  35697. if (yych == 'm') { gotoCase = 69; continue; };
  35698. { gotoCase = 68; continue; };
  35699. case 93:
  35700. yych = this._charAt(++cursor);
  35701. if (yych == 'd') { gotoCase = 69; continue; };
  35702. { gotoCase = 68; continue; };
  35703. case 94:
  35704. yych = this._charAt(++cursor);
  35705. if (yych == 'm') { gotoCase = 69; continue; };
  35706. { gotoCase = 68; continue; };
  35707. case 95:
  35708. yych = this._charAt(++cursor);
  35709. if (yych != 'r') { gotoCase = 51; continue; };
  35710. yych = this._charAt(++cursor);
  35711. if (yych == 'n') { gotoCase = 65; continue; };
  35712. { gotoCase = 51; continue; };
  35713. case 97:
  35714. yych = this._charAt(++cursor);
  35715. if (yych == 'd') { gotoCase = 65; continue; };
  35716. { gotoCase = 51; continue; };
  35717. case 98:
  35718. yych = this._charAt(++cursor);
  35719. if (yych == 'm') { gotoCase = 65; continue; };
  35720. { gotoCase = 51; continue; };
  35721. case 99:
  35722. yych = this._charAt(++cursor);
  35723. if (yych == 'z') { gotoCase = 65; continue; };
  35724. { gotoCase = 51; continue; };
  35725. case 100:
  35726. yych = this._charAt(++cursor);
  35727. if (yych != 'a') { gotoCase = 51; continue; };
  35728. yych = this._charAt(++cursor);
  35729. if (yych == 'd') { gotoCase = 65; continue; };
  35730. { gotoCase = 51; continue; };
  35731. case 102:
  35732. yych = this._charAt(++cursor);
  35733. if (yych == 'g') { gotoCase = 65; continue; };
  35734. { gotoCase = 51; continue; };
  35735. case 103:
  35736. yych = this._charAt(++cursor);
  35737. if (yych != 'q') { gotoCase = 51; continue; };
  35738. yych = this._charAt(++cursor);
  35739. if (yych != 'e') { gotoCase = 51; continue; };
  35740. yych = this._charAt(++cursor);
  35741. if (yych == 'm') { gotoCase = 65; continue; };
  35742. { gotoCase = 51; continue; };
  35743. case 106:
  35744. ++cursor;
  35745. yych = this._charAt(cursor);
  35746. if (yych <= '\f') {
  35747. if (yych == '\n') { gotoCase = 110; continue; };
  35748. { gotoCase = 106; continue; };
  35749. } else {
  35750. if (yych <= '\r') { gotoCase = 110; continue; };
  35751. if (yych != '*') { gotoCase = 106; continue; };
  35752. }
  35753. case 108:
  35754. ++cursor;
  35755. yych = this._charAt(cursor);
  35756. if (yych == '*') { gotoCase = 108; continue; };
  35757. if (yych == '/') { gotoCase = 112; continue; };
  35758. { gotoCase = 106; continue; };
  35759. case 110:
  35760. ++cursor;
  35761. this.setLexCondition(this._lexConditions.COMMENT);
  35762. { this.tokenType = "css-comment"; return cursor; }
  35763. case 112:
  35764. ++cursor;
  35765. { this.tokenType = "css-comment"; return cursor; }
  35766. case 114:
  35767. yyaccept = 0;
  35768. YYMARKER = ++cursor;
  35769. yych = this._charAt(cursor);
  35770. if (yych <= '.') {
  35771. if (yych <= '"') {
  35772. if (yych <= '\f') {
  35773. if (yych == '\n') { gotoCase = 32; continue; };
  35774. { gotoCase = 118; continue; };
  35775. } else {
  35776. if (yych <= '\r') { gotoCase = 32; continue; };
  35777. if (yych <= ' ') { gotoCase = 118; continue; };
  35778. { gotoCase = 114; continue; };
  35779. }
  35780. } else {
  35781. if (yych <= '\'') {
  35782. if (yych <= '%') { gotoCase = 118; continue; };
  35783. if (yych <= '&') { gotoCase = 114; continue; };
  35784. } else {
  35785. if (yych == '-') { gotoCase = 114; continue; };
  35786. { gotoCase = 118; continue; };
  35787. }
  35788. }
  35789. } else {
  35790. if (yych <= '\\') {
  35791. if (yych <= '=') {
  35792. if (yych <= '9') { gotoCase = 114; continue; };
  35793. if (yych <= '<') { gotoCase = 118; continue; };
  35794. { gotoCase = 114; continue; };
  35795. } else {
  35796. if (yych <= '?') { gotoCase = 118; continue; };
  35797. if (yych <= '[') { gotoCase = 114; continue; };
  35798. { gotoCase = 120; continue; };
  35799. }
  35800. } else {
  35801. if (yych <= '_') {
  35802. if (yych == '^') { gotoCase = 118; continue; };
  35803. { gotoCase = 114; continue; };
  35804. } else {
  35805. if (yych <= '`') { gotoCase = 118; continue; };
  35806. if (yych <= 'z') { gotoCase = 114; continue; };
  35807. { gotoCase = 118; continue; };
  35808. }
  35809. }
  35810. }
  35811. case 116:
  35812. ++cursor;
  35813. if ((yych = this._charAt(cursor)) <= '<') {
  35814. if (yych <= '\'') {
  35815. if (yych <= ' ') { gotoCase = 117; continue; };
  35816. if (yych <= '"') { gotoCase = 50; continue; };
  35817. if (yych >= '&') { gotoCase = 50; continue; };
  35818. } else {
  35819. if (yych <= '-') {
  35820. if (yych >= '-') { gotoCase = 50; continue; };
  35821. } else {
  35822. if (yych <= '.') { gotoCase = 117; continue; };
  35823. if (yych <= '9') { gotoCase = 50; continue; };
  35824. }
  35825. }
  35826. } else {
  35827. if (yych <= ']') {
  35828. if (yych <= '?') {
  35829. if (yych <= '=') { gotoCase = 50; continue; };
  35830. } else {
  35831. if (yych != '\\') { gotoCase = 50; continue; };
  35832. }
  35833. } else {
  35834. if (yych <= '_') {
  35835. if (yych >= '_') { gotoCase = 50; continue; };
  35836. } else {
  35837. if (yych <= '`') { gotoCase = 117; continue; };
  35838. if (yych <= 'z') { gotoCase = 50; continue; };
  35839. }
  35840. }
  35841. }
  35842. case 117:
  35843. { return this._stringToken(cursor, true); }
  35844. case 118:
  35845. ++cursor;
  35846. yych = this._charAt(cursor);
  35847. if (yych <= '\r') {
  35848. if (yych == '\n') { gotoCase = 68; continue; };
  35849. if (yych <= '\f') { gotoCase = 118; continue; };
  35850. { gotoCase = 68; continue; };
  35851. } else {
  35852. if (yych <= '\'') {
  35853. if (yych <= '&') { gotoCase = 118; continue; };
  35854. { gotoCase = 123; continue; };
  35855. } else {
  35856. if (yych != '\\') { gotoCase = 118; continue; };
  35857. }
  35858. }
  35859. case 120:
  35860. ++cursor;
  35861. yych = this._charAt(cursor);
  35862. if (yych <= 'a') {
  35863. if (yych <= '!') {
  35864. if (yych <= '\n') {
  35865. if (yych <= '\t') { gotoCase = 68; continue; };
  35866. } else {
  35867. if (yych != '\r') { gotoCase = 68; continue; };
  35868. }
  35869. } else {
  35870. if (yych <= '\'') {
  35871. if (yych <= '"') { gotoCase = 118; continue; };
  35872. if (yych <= '&') { gotoCase = 68; continue; };
  35873. { gotoCase = 118; continue; };
  35874. } else {
  35875. if (yych == '\\') { gotoCase = 118; continue; };
  35876. { gotoCase = 68; continue; };
  35877. }
  35878. }
  35879. } else {
  35880. if (yych <= 'q') {
  35881. if (yych <= 'f') {
  35882. if (yych <= 'b') { gotoCase = 118; continue; };
  35883. if (yych <= 'e') { gotoCase = 68; continue; };
  35884. { gotoCase = 118; continue; };
  35885. } else {
  35886. if (yych == 'n') { gotoCase = 118; continue; };
  35887. { gotoCase = 68; continue; };
  35888. }
  35889. } else {
  35890. if (yych <= 't') {
  35891. if (yych == 's') { gotoCase = 68; continue; };
  35892. { gotoCase = 118; continue; };
  35893. } else {
  35894. if (yych == 'v') { gotoCase = 118; continue; };
  35895. { gotoCase = 68; continue; };
  35896. }
  35897. }
  35898. }
  35899. ++cursor;
  35900. this.setLexCondition(this._lexConditions.SSTRING);
  35901. { return this._stringToken(cursor); }
  35902. case 123:
  35903. yych = this._charAt(++cursor);
  35904. { gotoCase = 117; continue; };
  35905. case 124:
  35906. ++cursor;
  35907. yych = this._charAt(cursor);
  35908. if (yych <= '<') {
  35909. if (yych <= '\'') {
  35910. if (yych <= ' ') { gotoCase = 126; continue; };
  35911. if (yych <= '"') { gotoCase = 124; continue; };
  35912. if (yych >= '&') { gotoCase = 124; continue; };
  35913. } else {
  35914. if (yych <= '-') {
  35915. if (yych >= '-') { gotoCase = 124; continue; };
  35916. } else {
  35917. if (yych <= '.') { gotoCase = 126; continue; };
  35918. if (yych <= '9') { gotoCase = 124; continue; };
  35919. }
  35920. }
  35921. } else {
  35922. if (yych <= ']') {
  35923. if (yych <= '?') {
  35924. if (yych <= '=') { gotoCase = 124; continue; };
  35925. } else {
  35926. if (yych != '\\') { gotoCase = 124; continue; };
  35927. }
  35928. } else {
  35929. if (yych <= '_') {
  35930. if (yych >= '_') { gotoCase = 124; continue; };
  35931. } else {
  35932. if (yych <= '`') { gotoCase = 126; continue; };
  35933. if (yych <= 'z') { gotoCase = 124; continue; };
  35934. }
  35935. }
  35936. }
  35937. case 126:
  35938. {
  35939. if (this._condition.parseCondition === this._condition.parseCondition.INITIAL || this._condition.parseCondition === this._condition.parseCondition.AT_RULE)
  35940. this._setParseCondition(this._parseConditions.PROPERTY);
  35941. this.tokenType = "scss-variable";
  35942. return cursor;
  35943. }
  35944. case 127:
  35945. ++cursor;
  35946. yych = this._charAt(cursor);
  35947. if (yych <= '@') {
  35948. if (yych <= '/') { gotoCase = 129; continue; };
  35949. if (yych <= '9') { gotoCase = 127; continue; };
  35950. } else {
  35951. if (yych <= 'Z') { gotoCase = 127; continue; };
  35952. if (yych <= '`') { gotoCase = 129; continue; };
  35953. if (yych <= 'z') { gotoCase = 127; continue; };
  35954. }
  35955. case 129:
  35956. {
  35957. if (this._isPropertyValue())
  35958. this.tokenType = "css-color";
  35959. else if (this._condition.parseCondition === this._parseConditions.INITIAL)
  35960. this.tokenType = "css-selector";
  35961. else
  35962. this.tokenType = null;
  35963. return cursor;
  35964. }
  35965. case 130:
  35966. yyaccept = 0;
  35967. YYMARKER = ++cursor;
  35968. yych = this._charAt(cursor);
  35969. if (yych <= '.') {
  35970. if (yych <= '!') {
  35971. if (yych <= '\f') {
  35972. if (yych == '\n') { gotoCase = 32; continue; };
  35973. } else {
  35974. if (yych <= '\r') { gotoCase = 32; continue; };
  35975. if (yych >= '!') { gotoCase = 130; continue; };
  35976. }
  35977. } else {
  35978. if (yych <= '\'') {
  35979. if (yych <= '"') { gotoCase = 116; continue; };
  35980. if (yych >= '&') { gotoCase = 130; continue; };
  35981. } else {
  35982. if (yych == '-') { gotoCase = 130; continue; };
  35983. }
  35984. }
  35985. } else {
  35986. if (yych <= '\\') {
  35987. if (yych <= '=') {
  35988. if (yych <= '9') { gotoCase = 130; continue; };
  35989. if (yych >= '=') { gotoCase = 130; continue; };
  35990. } else {
  35991. if (yych <= '?') { gotoCase = 132; continue; };
  35992. if (yych <= '[') { gotoCase = 130; continue; };
  35993. { gotoCase = 134; continue; };
  35994. }
  35995. } else {
  35996. if (yych <= '_') {
  35997. if (yych != '^') { gotoCase = 130; continue; };
  35998. } else {
  35999. if (yych <= '`') { gotoCase = 132; continue; };
  36000. if (yych <= 'z') { gotoCase = 130; continue; };
  36001. }
  36002. }
  36003. }
  36004. case 132:
  36005. ++cursor;
  36006. yych = this._charAt(cursor);
  36007. if (yych <= '\r') {
  36008. if (yych == '\n') { gotoCase = 68; continue; };
  36009. if (yych <= '\f') { gotoCase = 132; continue; };
  36010. { gotoCase = 68; continue; };
  36011. } else {
  36012. if (yych <= '"') {
  36013. if (yych <= '!') { gotoCase = 132; continue; };
  36014. { gotoCase = 123; continue; };
  36015. } else {
  36016. if (yych != '\\') { gotoCase = 132; continue; };
  36017. }
  36018. }
  36019. case 134:
  36020. ++cursor;
  36021. yych = this._charAt(cursor);
  36022. if (yych <= 'a') {
  36023. if (yych <= '!') {
  36024. if (yych <= '\n') {
  36025. if (yych <= '\t') { gotoCase = 68; continue; };
  36026. } else {
  36027. if (yych != '\r') { gotoCase = 68; continue; };
  36028. }
  36029. } else {
  36030. if (yych <= '\'') {
  36031. if (yych <= '"') { gotoCase = 132; continue; };
  36032. if (yych <= '&') { gotoCase = 68; continue; };
  36033. { gotoCase = 132; continue; };
  36034. } else {
  36035. if (yych == '\\') { gotoCase = 132; continue; };
  36036. { gotoCase = 68; continue; };
  36037. }
  36038. }
  36039. } else {
  36040. if (yych <= 'q') {
  36041. if (yych <= 'f') {
  36042. if (yych <= 'b') { gotoCase = 132; continue; };
  36043. if (yych <= 'e') { gotoCase = 68; continue; };
  36044. { gotoCase = 132; continue; };
  36045. } else {
  36046. if (yych == 'n') { gotoCase = 132; continue; };
  36047. { gotoCase = 68; continue; };
  36048. }
  36049. } else {
  36050. if (yych <= 't') {
  36051. if (yych == 's') { gotoCase = 68; continue; };
  36052. { gotoCase = 132; continue; };
  36053. } else {
  36054. if (yych == 'v') { gotoCase = 132; continue; };
  36055. { gotoCase = 68; continue; };
  36056. }
  36057. }
  36058. }
  36059. ++cursor;
  36060. this.setLexCondition(this._lexConditions.DSTRING);
  36061. { return this._stringToken(cursor); }
  36062.  
  36063. case this.case_SSTRING:
  36064. yych = this._charAt(cursor);
  36065. if (yych <= '\r') {
  36066. if (yych == '\n') { gotoCase = 141; continue; };
  36067. if (yych <= '\f') { gotoCase = 140; continue; };
  36068. { gotoCase = 141; continue; };
  36069. } else {
  36070. if (yych <= '\'') {
  36071. if (yych <= '&') { gotoCase = 140; continue; };
  36072. { gotoCase = 143; continue; };
  36073. } else {
  36074. if (yych == '\\') { gotoCase = 145; continue; };
  36075. { gotoCase = 140; continue; };
  36076. }
  36077. }
  36078. case 139:
  36079. { return this._stringToken(cursor); }
  36080. case 140:
  36081. yyaccept = 0;
  36082. yych = this._charAt(YYMARKER = ++cursor);
  36083. { gotoCase = 147; continue; };
  36084. case 141:
  36085. ++cursor;
  36086. case 142:
  36087. { this.tokenType = null; return cursor; }
  36088. case 143:
  36089. ++cursor;
  36090. case 144:
  36091. this.setLexCondition(this._lexConditions.INITIAL);
  36092. { return this._stringToken(cursor, true); }
  36093. case 145:
  36094. yych = this._charAt(++cursor);
  36095. if (yych <= 'e') {
  36096. if (yych <= '\'') {
  36097. if (yych == '"') { gotoCase = 146; continue; };
  36098. if (yych <= '&') { gotoCase = 142; continue; };
  36099. } else {
  36100. if (yych <= '\\') {
  36101. if (yych <= '[') { gotoCase = 142; continue; };
  36102. } else {
  36103. if (yych != 'b') { gotoCase = 142; continue; };
  36104. }
  36105. }
  36106. } else {
  36107. if (yych <= 'r') {
  36108. if (yych <= 'm') {
  36109. if (yych >= 'g') { gotoCase = 142; continue; };
  36110. } else {
  36111. if (yych <= 'n') { gotoCase = 146; continue; };
  36112. if (yych <= 'q') { gotoCase = 142; continue; };
  36113. }
  36114. } else {
  36115. if (yych <= 't') {
  36116. if (yych <= 's') { gotoCase = 142; continue; };
  36117. } else {
  36118. if (yych != 'v') { gotoCase = 142; continue; };
  36119. }
  36120. }
  36121. }
  36122. case 146:
  36123. yyaccept = 0;
  36124. YYMARKER = ++cursor;
  36125. yych = this._charAt(cursor);
  36126. case 147:
  36127. if (yych <= '\r') {
  36128. if (yych == '\n') { gotoCase = 139; continue; };
  36129. if (yych <= '\f') { gotoCase = 146; continue; };
  36130. { gotoCase = 139; continue; };
  36131. } else {
  36132. if (yych <= '\'') {
  36133. if (yych <= '&') { gotoCase = 146; continue; };
  36134. { gotoCase = 150; continue; };
  36135. } else {
  36136. if (yych != '\\') { gotoCase = 146; continue; };
  36137. }
  36138. }
  36139. ++cursor;
  36140. yych = this._charAt(cursor);
  36141. if (yych <= 'e') {
  36142. if (yych <= '\'') {
  36143. if (yych == '"') { gotoCase = 146; continue; };
  36144. if (yych >= '\'') { gotoCase = 146; continue; };
  36145. } else {
  36146. if (yych <= '\\') {
  36147. if (yych >= '\\') { gotoCase = 146; continue; };
  36148. } else {
  36149. if (yych == 'b') { gotoCase = 146; continue; };
  36150. }
  36151. }
  36152. } else {
  36153. if (yych <= 'r') {
  36154. if (yych <= 'm') {
  36155. if (yych <= 'f') { gotoCase = 146; continue; };
  36156. } else {
  36157. if (yych <= 'n') { gotoCase = 146; continue; };
  36158. if (yych >= 'r') { gotoCase = 146; continue; };
  36159. }
  36160. } else {
  36161. if (yych <= 't') {
  36162. if (yych >= 't') { gotoCase = 146; continue; };
  36163. } else {
  36164. if (yych == 'v') { gotoCase = 146; continue; };
  36165. }
  36166. }
  36167. }
  36168. cursor = YYMARKER;
  36169. { gotoCase = 139; continue; };
  36170. case 150:
  36171. ++cursor;
  36172. yych = this._charAt(cursor);
  36173. { gotoCase = 144; continue; };
  36174. }
  36175.  
  36176. }
  36177. },
  36178.  
  36179. __proto__: WebInspector.SourceTokenizer.prototype
  36180. }
  36181.  
  36182.  
  36183.  
  36184.  
  36185.  
  36186.  
  36187.  
  36188.  
  36189.  
  36190.  
  36191.  
  36192.  
  36193.  
  36194.  
  36195.  
  36196.  
  36197.  
  36198.  
  36199.  
  36200. WebInspector.SourceHTMLTokenizer = function()
  36201. {
  36202. WebInspector.SourceTokenizer.call(this);
  36203.  
  36204.  
  36205. this._lexConditions = {
  36206. INITIAL: 0,
  36207. COMMENT: 1,
  36208. DOCTYPE: 2,
  36209. TAG: 3,
  36210. DSTRING: 4,
  36211. SSTRING: 5
  36212. };
  36213. this.case_INITIAL = 1000;
  36214. this.case_COMMENT = 1001;
  36215. this.case_DOCTYPE = 1002;
  36216. this.case_TAG = 1003;
  36217. this.case_DSTRING = 1004;
  36218. this.case_SSTRING = 1005;
  36219.  
  36220. this._parseConditions = {
  36221. INITIAL: 0,
  36222. ATTRIBUTE: 1,
  36223. ATTRIBUTE_VALUE: 2,
  36224. LINKIFY: 4,
  36225. A_NODE: 8,
  36226. SCRIPT: 16,
  36227. STYLE: 32
  36228. };
  36229.  
  36230. this.condition = this.createInitialCondition();
  36231. }
  36232.  
  36233. WebInspector.SourceHTMLTokenizer.prototype = {
  36234. createInitialCondition: function()
  36235. {
  36236. return { lexCondition: this._lexConditions.INITIAL, parseCondition: this._parseConditions.INITIAL };
  36237. },
  36238.  
  36239. set line(line) {
  36240. if (this._condition.internalJavaScriptTokenizerCondition) {
  36241. var match = /<\/script/i.exec(line);
  36242. if (match) {
  36243. this._internalJavaScriptTokenizer.line = line.substring(0, match.index);
  36244. } else
  36245. this._internalJavaScriptTokenizer.line = line;
  36246. } else if (this._condition.internalCSSTokenizerCondition) {
  36247. var match = /<\/style/i.exec(line);
  36248. if (match) {
  36249. this._internalCSSTokenizer.line = line.substring(0, match.index);
  36250. } else
  36251. this._internalCSSTokenizer.line = line;
  36252. }
  36253. this._line = line;
  36254. },
  36255.  
  36256. _isExpectingAttribute: function()
  36257. {
  36258. return this._condition.parseCondition & this._parseConditions.ATTRIBUTE;
  36259. },
  36260.  
  36261. _isExpectingAttributeValue: function()
  36262. {
  36263. return this._condition.parseCondition & this._parseConditions.ATTRIBUTE_VALUE;
  36264. },
  36265.  
  36266. _setExpectingAttribute: function()
  36267. {
  36268. if (this._isExpectingAttributeValue())
  36269. this._condition.parseCondition ^= this._parseConditions.ATTRIBUTE_VALUE;
  36270. this._condition.parseCondition |= this._parseConditions.ATTRIBUTE;
  36271. },
  36272.  
  36273. _setExpectingAttributeValue: function()
  36274. {
  36275. if (this._isExpectingAttribute())
  36276. this._condition.parseCondition ^= this._parseConditions.ATTRIBUTE;
  36277. this._condition.parseCondition |= this._parseConditions.ATTRIBUTE_VALUE;
  36278. },
  36279.  
  36280.  
  36281. _stringToken: function(cursor, stringEnds)
  36282. {
  36283. if (!this._isExpectingAttributeValue()) {
  36284. this.tokenType = null;
  36285. return cursor;
  36286. }
  36287. this.tokenType = this._attrValueTokenType();
  36288. if (stringEnds)
  36289. this._setExpectingAttribute();
  36290. return cursor;
  36291. },
  36292.  
  36293. _attrValueTokenType: function()
  36294. {
  36295. if (this._condition.parseCondition & this._parseConditions.LINKIFY) {
  36296. if (this._condition.parseCondition & this._parseConditions.A_NODE)
  36297. return "html-external-link";
  36298. return "html-resource-link";
  36299. }
  36300. return "html-attribute-value";
  36301. },
  36302.  
  36303. get _internalJavaScriptTokenizer()
  36304. {
  36305. return WebInspector.SourceTokenizer.Registry.getInstance().getTokenizer("text/javascript");
  36306. },
  36307.  
  36308. get _internalCSSTokenizer()
  36309. {
  36310. return WebInspector.SourceTokenizer.Registry.getInstance().getTokenizer("text/css");
  36311. },
  36312.  
  36313. scriptStarted: function(cursor)
  36314. {
  36315. this._condition.internalJavaScriptTokenizerCondition = this._internalJavaScriptTokenizer.createInitialCondition();
  36316. },
  36317.  
  36318. scriptEnded: function(cursor)
  36319. {
  36320. },
  36321.  
  36322. styleSheetStarted: function(cursor)
  36323. {
  36324. this._condition.internalCSSTokenizerCondition = this._internalCSSTokenizer.createInitialCondition();
  36325. },
  36326.  
  36327. styleSheetEnded: function(cursor)
  36328. {
  36329. },
  36330.  
  36331. nextToken: function(cursor)
  36332. {
  36333. if (this._condition.internalJavaScriptTokenizerCondition) {
  36334.  
  36335. this.line = this._line;
  36336. if (cursor !== this._internalJavaScriptTokenizer._line.length) {
  36337.  
  36338. this._internalJavaScriptTokenizer.condition = this._condition.internalJavaScriptTokenizerCondition;
  36339. var result = this._internalJavaScriptTokenizer.nextToken(cursor);
  36340. this.tokenType = this._internalJavaScriptTokenizer.tokenType;
  36341. this._condition.internalJavaScriptTokenizerCondition = this._internalJavaScriptTokenizer.condition;
  36342. return result;
  36343. } else if (cursor !== this._line.length)
  36344. delete this._condition.internalJavaScriptTokenizerCondition;
  36345. } else if (this._condition.internalCSSTokenizerCondition) {
  36346.  
  36347. this.line = this._line;
  36348. if (cursor !== this._internalCSSTokenizer._line.length) {
  36349.  
  36350. this._internalCSSTokenizer.condition = this._condition.internalCSSTokenizerCondition;
  36351. var result = this._internalCSSTokenizer.nextToken(cursor);
  36352. this.tokenType = this._internalCSSTokenizer.tokenType;
  36353. this._condition.internalCSSTokenizerCondition = this._internalCSSTokenizer.condition;
  36354. return result;
  36355. } else if (cursor !== this._line.length)
  36356. delete this._condition.internalCSSTokenizerCondition;
  36357. }
  36358.  
  36359. var cursorOnEnter = cursor;
  36360. var gotoCase = 1;
  36361. var YYMARKER;
  36362. while (1) {
  36363. switch (gotoCase)
  36364.  
  36365.  
  36366. {
  36367. case 1: var yych;
  36368. var yyaccept = 0;
  36369. if (this.getLexCondition() < 3) {
  36370. if (this.getLexCondition() < 1) {
  36371. { gotoCase = this.case_INITIAL; continue; };
  36372. } else {
  36373. if (this.getLexCondition() < 2) {
  36374. { gotoCase = this.case_COMMENT; continue; };
  36375. } else {
  36376. { gotoCase = this.case_DOCTYPE; continue; };
  36377. }
  36378. }
  36379. } else {
  36380. if (this.getLexCondition() < 4) {
  36381. { gotoCase = this.case_TAG; continue; };
  36382. } else {
  36383. if (this.getLexCondition() < 5) {
  36384. { gotoCase = this.case_DSTRING; continue; };
  36385. } else {
  36386. { gotoCase = this.case_SSTRING; continue; };
  36387. }
  36388. }
  36389. }
  36390.  
  36391. case this.case_COMMENT:
  36392.  
  36393. yych = this._charAt(cursor);
  36394. if (yych <= '\f') {
  36395. if (yych == '\n') { gotoCase = 4; continue; };
  36396. { gotoCase = 3; continue; };
  36397. } else {
  36398. if (yych <= '\r') { gotoCase = 4; continue; };
  36399. if (yych == '-') { gotoCase = 6; continue; };
  36400. { gotoCase = 3; continue; };
  36401. }
  36402. case 2:
  36403. { this.tokenType = "html-comment"; return cursor; }
  36404. case 3:
  36405. yyaccept = 0;
  36406. yych = this._charAt(YYMARKER = ++cursor);
  36407. { gotoCase = 9; continue; };
  36408. case 4:
  36409. ++cursor;
  36410. case 5:
  36411. { this.tokenType = null; return cursor; }
  36412. case 6:
  36413. yyaccept = 1;
  36414. yych = this._charAt(YYMARKER = ++cursor);
  36415. if (yych != '-') { gotoCase = 5; continue; };
  36416. case 7:
  36417. ++cursor;
  36418. yych = this._charAt(cursor);
  36419. if (yych == '>') { gotoCase = 10; continue; };
  36420. case 8:
  36421. yyaccept = 0;
  36422. YYMARKER = ++cursor;
  36423. yych = this._charAt(cursor);
  36424. case 9:
  36425. if (yych <= '\f') {
  36426. if (yych == '\n') { gotoCase = 2; continue; };
  36427. { gotoCase = 8; continue; };
  36428. } else {
  36429. if (yych <= '\r') { gotoCase = 2; continue; };
  36430. if (yych == '-') { gotoCase = 12; continue; };
  36431. { gotoCase = 8; continue; };
  36432. }
  36433. case 10:
  36434. ++cursor;
  36435. this.setLexCondition(this._lexConditions.INITIAL);
  36436. { this.tokenType = "html-comment"; return cursor; }
  36437. case 12:
  36438. ++cursor;
  36439. yych = this._charAt(cursor);
  36440. if (yych == '-') { gotoCase = 7; continue; };
  36441. cursor = YYMARKER;
  36442. if (yyaccept <= 0) {
  36443. { gotoCase = 2; continue; };
  36444. } else {
  36445. { gotoCase = 5; continue; };
  36446. }
  36447.  
  36448. case this.case_DOCTYPE:
  36449. yych = this._charAt(cursor);
  36450. if (yych <= '\f') {
  36451. if (yych == '\n') { gotoCase = 18; continue; };
  36452. { gotoCase = 17; continue; };
  36453. } else {
  36454. if (yych <= '\r') { gotoCase = 18; continue; };
  36455. if (yych == '>') { gotoCase = 20; continue; };
  36456. { gotoCase = 17; continue; };
  36457. }
  36458. case 16:
  36459. { this.tokenType = "html-doctype"; return cursor; }
  36460. case 17:
  36461. yych = this._charAt(++cursor);
  36462. { gotoCase = 23; continue; };
  36463. case 18:
  36464. ++cursor;
  36465. { this.tokenType = null; return cursor; }
  36466. case 20:
  36467. ++cursor;
  36468. this.setLexCondition(this._lexConditions.INITIAL);
  36469. { this.tokenType = "html-doctype"; return cursor; }
  36470. case 22:
  36471. ++cursor;
  36472. yych = this._charAt(cursor);
  36473. case 23:
  36474. if (yych <= '\f') {
  36475. if (yych == '\n') { gotoCase = 16; continue; };
  36476. { gotoCase = 22; continue; };
  36477. } else {
  36478. if (yych <= '\r') { gotoCase = 16; continue; };
  36479. if (yych == '>') { gotoCase = 16; continue; };
  36480. { gotoCase = 22; continue; };
  36481. }
  36482.  
  36483. case this.case_DSTRING:
  36484. yych = this._charAt(cursor);
  36485. if (yych <= '\f') {
  36486. if (yych == '\n') { gotoCase = 28; continue; };
  36487. { gotoCase = 27; continue; };
  36488. } else {
  36489. if (yych <= '\r') { gotoCase = 28; continue; };
  36490. if (yych == '"') { gotoCase = 30; continue; };
  36491. { gotoCase = 27; continue; };
  36492. }
  36493. case 26:
  36494. { return this._stringToken(cursor); }
  36495. case 27:
  36496. yych = this._charAt(++cursor);
  36497. { gotoCase = 34; continue; };
  36498. case 28:
  36499. ++cursor;
  36500. { this.tokenType = null; return cursor; }
  36501. case 30:
  36502. ++cursor;
  36503. case 31:
  36504. this.setLexCondition(this._lexConditions.TAG);
  36505. { return this._stringToken(cursor, true); }
  36506. case 32:
  36507. yych = this._charAt(++cursor);
  36508. { gotoCase = 31; continue; };
  36509. case 33:
  36510. ++cursor;
  36511. yych = this._charAt(cursor);
  36512. case 34:
  36513. if (yych <= '\f') {
  36514. if (yych == '\n') { gotoCase = 26; continue; };
  36515. { gotoCase = 33; continue; };
  36516. } else {
  36517. if (yych <= '\r') { gotoCase = 26; continue; };
  36518. if (yych == '"') { gotoCase = 32; continue; };
  36519. { gotoCase = 33; continue; };
  36520. }
  36521.  
  36522. case this.case_INITIAL:
  36523. yych = this._charAt(cursor);
  36524. if (yych == '<') { gotoCase = 39; continue; };
  36525. ++cursor;
  36526. { this.tokenType = null; return cursor; }
  36527. case 39:
  36528. yyaccept = 0;
  36529. yych = this._charAt(YYMARKER = ++cursor);
  36530. if (yych <= '/') {
  36531. if (yych == '!') { gotoCase = 44; continue; };
  36532. if (yych >= '/') { gotoCase = 41; continue; };
  36533. } else {
  36534. if (yych <= 'S') {
  36535. if (yych >= 'S') { gotoCase = 42; continue; };
  36536. } else {
  36537. if (yych == 's') { gotoCase = 42; continue; };
  36538. }
  36539. }
  36540. case 40:
  36541. this.setLexCondition(this._lexConditions.TAG);
  36542. {
  36543. if (this._condition.parseCondition & (this._parseConditions.SCRIPT | this._parseConditions.STYLE)) {
  36544.  
  36545. this.setLexCondition(this._lexConditions.INITIAL);
  36546. this.tokenType = null;
  36547. return cursor;
  36548. }
  36549.  
  36550. this._condition.parseCondition = this._parseConditions.INITIAL;
  36551. this.tokenType = "html-tag";
  36552. return cursor;
  36553. }
  36554. case 41:
  36555. yyaccept = 0;
  36556. yych = this._charAt(YYMARKER = ++cursor);
  36557. if (yych == 'S') { gotoCase = 73; continue; };
  36558. if (yych == 's') { gotoCase = 73; continue; };
  36559. { gotoCase = 40; continue; };
  36560. case 42:
  36561. yych = this._charAt(++cursor);
  36562. if (yych <= 'T') {
  36563. if (yych == 'C') { gotoCase = 62; continue; };
  36564. if (yych >= 'T') { gotoCase = 63; continue; };
  36565. } else {
  36566. if (yych <= 'c') {
  36567. if (yych >= 'c') { gotoCase = 62; continue; };
  36568. } else {
  36569. if (yych == 't') { gotoCase = 63; continue; };
  36570. }
  36571. }
  36572. case 43:
  36573. cursor = YYMARKER;
  36574. { gotoCase = 40; continue; };
  36575. case 44:
  36576. yych = this._charAt(++cursor);
  36577. if (yych <= 'C') {
  36578. if (yych != '-') { gotoCase = 43; continue; };
  36579. } else {
  36580. if (yych <= 'D') { gotoCase = 46; continue; };
  36581. if (yych == 'd') { gotoCase = 46; continue; };
  36582. { gotoCase = 43; continue; };
  36583. }
  36584. yych = this._charAt(++cursor);
  36585. if (yych == '-') { gotoCase = 54; continue; };
  36586. { gotoCase = 43; continue; };
  36587. case 46:
  36588. yych = this._charAt(++cursor);
  36589. if (yych == 'O') { gotoCase = 47; continue; };
  36590. if (yych != 'o') { gotoCase = 43; continue; };
  36591. case 47:
  36592. yych = this._charAt(++cursor);
  36593. if (yych == 'C') { gotoCase = 48; continue; };
  36594. if (yych != 'c') { gotoCase = 43; continue; };
  36595. case 48:
  36596. yych = this._charAt(++cursor);
  36597. if (yych == 'T') { gotoCase = 49; continue; };
  36598. if (yych != 't') { gotoCase = 43; continue; };
  36599. case 49:
  36600. yych = this._charAt(++cursor);
  36601. if (yych == 'Y') { gotoCase = 50; continue; };
  36602. if (yych != 'y') { gotoCase = 43; continue; };
  36603. case 50:
  36604. yych = this._charAt(++cursor);
  36605. if (yych == 'P') { gotoCase = 51; continue; };
  36606. if (yych != 'p') { gotoCase = 43; continue; };
  36607. case 51:
  36608. yych = this._charAt(++cursor);
  36609. if (yych == 'E') { gotoCase = 52; continue; };
  36610. if (yych != 'e') { gotoCase = 43; continue; };
  36611. case 52:
  36612. ++cursor;
  36613. this.setLexCondition(this._lexConditions.DOCTYPE);
  36614. { this.tokenType = "html-doctype"; return cursor; }
  36615. case 54:
  36616. ++cursor;
  36617. yych = this._charAt(cursor);
  36618. if (yych <= '\f') {
  36619. if (yych == '\n') { gotoCase = 57; continue; };
  36620. { gotoCase = 54; continue; };
  36621. } else {
  36622. if (yych <= '\r') { gotoCase = 57; continue; };
  36623. if (yych != '-') { gotoCase = 54; continue; };
  36624. }
  36625. ++cursor;
  36626. yych = this._charAt(cursor);
  36627. if (yych == '-') { gotoCase = 59; continue; };
  36628. { gotoCase = 43; continue; };
  36629. case 57:
  36630. ++cursor;
  36631. this.setLexCondition(this._lexConditions.COMMENT);
  36632. { this.tokenType = "html-comment"; return cursor; }
  36633. case 59:
  36634. ++cursor;
  36635. yych = this._charAt(cursor);
  36636. if (yych != '>') { gotoCase = 54; continue; };
  36637. ++cursor;
  36638. { this.tokenType = "html-comment"; return cursor; }
  36639. case 62:
  36640. yych = this._charAt(++cursor);
  36641. if (yych == 'R') { gotoCase = 68; continue; };
  36642. if (yych == 'r') { gotoCase = 68; continue; };
  36643. { gotoCase = 43; continue; };
  36644. case 63:
  36645. yych = this._charAt(++cursor);
  36646. if (yych == 'Y') { gotoCase = 64; continue; };
  36647. if (yych != 'y') { gotoCase = 43; continue; };
  36648. case 64:
  36649. yych = this._charAt(++cursor);
  36650. if (yych == 'L') { gotoCase = 65; continue; };
  36651. if (yych != 'l') { gotoCase = 43; continue; };
  36652. case 65:
  36653. yych = this._charAt(++cursor);
  36654. if (yych == 'E') { gotoCase = 66; continue; };
  36655. if (yych != 'e') { gotoCase = 43; continue; };
  36656. case 66:
  36657. ++cursor;
  36658. this.setLexCondition(this._lexConditions.TAG);
  36659. {
  36660. if (this._condition.parseCondition & this._parseConditions.STYLE) {
  36661.  
  36662. this.setLexCondition(this._lexConditions.INITIAL);
  36663. this.tokenType = null;
  36664. return cursor;
  36665. }
  36666. this.tokenType = "html-tag";
  36667. this._condition.parseCondition = this._parseConditions.STYLE;
  36668. this._setExpectingAttribute();
  36669. return cursor;
  36670. }
  36671. case 68:
  36672. yych = this._charAt(++cursor);
  36673. if (yych == 'I') { gotoCase = 69; continue; };
  36674. if (yych != 'i') { gotoCase = 43; continue; };
  36675. case 69:
  36676. yych = this._charAt(++cursor);
  36677. if (yych == 'P') { gotoCase = 70; continue; };
  36678. if (yych != 'p') { gotoCase = 43; continue; };
  36679. case 70:
  36680. yych = this._charAt(++cursor);
  36681. if (yych == 'T') { gotoCase = 71; continue; };
  36682. if (yych != 't') { gotoCase = 43; continue; };
  36683. case 71:
  36684. ++cursor;
  36685. this.setLexCondition(this._lexConditions.TAG);
  36686. {
  36687. if (this._condition.parseCondition & this._parseConditions.SCRIPT) {
  36688.  
  36689. this.setLexCondition(this._lexConditions.INITIAL);
  36690. this.tokenType = null;
  36691. return cursor;
  36692. }
  36693. this.tokenType = "html-tag";
  36694. this._condition.parseCondition = this._parseConditions.SCRIPT;
  36695. this._setExpectingAttribute();
  36696. return cursor;
  36697. }
  36698. case 73:
  36699. yych = this._charAt(++cursor);
  36700. if (yych <= 'T') {
  36701. if (yych == 'C') { gotoCase = 75; continue; };
  36702. if (yych <= 'S') { gotoCase = 43; continue; };
  36703. } else {
  36704. if (yych <= 'c') {
  36705. if (yych <= 'b') { gotoCase = 43; continue; };
  36706. { gotoCase = 75; continue; };
  36707. } else {
  36708. if (yych != 't') { gotoCase = 43; continue; };
  36709. }
  36710. }
  36711. yych = this._charAt(++cursor);
  36712. if (yych == 'Y') { gotoCase = 81; continue; };
  36713. if (yych == 'y') { gotoCase = 81; continue; };
  36714. { gotoCase = 43; continue; };
  36715. case 75:
  36716. yych = this._charAt(++cursor);
  36717. if (yych == 'R') { gotoCase = 76; continue; };
  36718. if (yych != 'r') { gotoCase = 43; continue; };
  36719. case 76:
  36720. yych = this._charAt(++cursor);
  36721. if (yych == 'I') { gotoCase = 77; continue; };
  36722. if (yych != 'i') { gotoCase = 43; continue; };
  36723. case 77:
  36724. yych = this._charAt(++cursor);
  36725. if (yych == 'P') { gotoCase = 78; continue; };
  36726. if (yych != 'p') { gotoCase = 43; continue; };
  36727. case 78:
  36728. yych = this._charAt(++cursor);
  36729. if (yych == 'T') { gotoCase = 79; continue; };
  36730. if (yych != 't') { gotoCase = 43; continue; };
  36731. case 79:
  36732. ++cursor;
  36733. this.setLexCondition(this._lexConditions.TAG);
  36734. {
  36735. this.tokenType = "html-tag";
  36736. this._condition.parseCondition = this._parseConditions.INITIAL;
  36737. this.scriptEnded(cursor - 8);
  36738. return cursor;
  36739. }
  36740. case 81:
  36741. yych = this._charAt(++cursor);
  36742. if (yych == 'L') { gotoCase = 82; continue; };
  36743. if (yych != 'l') { gotoCase = 43; continue; };
  36744. case 82:
  36745. yych = this._charAt(++cursor);
  36746. if (yych == 'E') { gotoCase = 83; continue; };
  36747. if (yych != 'e') { gotoCase = 43; continue; };
  36748. case 83:
  36749. ++cursor;
  36750. this.setLexCondition(this._lexConditions.TAG);
  36751. {
  36752. this.tokenType = "html-tag";
  36753. this._condition.parseCondition = this._parseConditions.INITIAL;
  36754. this.styleSheetEnded(cursor - 7);
  36755. return cursor;
  36756. }
  36757.  
  36758. case this.case_SSTRING:
  36759. yych = this._charAt(cursor);
  36760. if (yych <= '\f') {
  36761. if (yych == '\n') { gotoCase = 89; continue; };
  36762. { gotoCase = 88; continue; };
  36763. } else {
  36764. if (yych <= '\r') { gotoCase = 89; continue; };
  36765. if (yych == '\'') { gotoCase = 91; continue; };
  36766. { gotoCase = 88; continue; };
  36767. }
  36768. case 87:
  36769. { return this._stringToken(cursor); }
  36770. case 88:
  36771. yych = this._charAt(++cursor);
  36772. { gotoCase = 95; continue; };
  36773. case 89:
  36774. ++cursor;
  36775. { this.tokenType = null; return cursor; }
  36776. case 91:
  36777. ++cursor;
  36778. case 92:
  36779. this.setLexCondition(this._lexConditions.TAG);
  36780. { return this._stringToken(cursor, true); }
  36781. case 93:
  36782. yych = this._charAt(++cursor);
  36783. { gotoCase = 92; continue; };
  36784. case 94:
  36785. ++cursor;
  36786. yych = this._charAt(cursor);
  36787. case 95:
  36788. if (yych <= '\f') {
  36789. if (yych == '\n') { gotoCase = 87; continue; };
  36790. { gotoCase = 94; continue; };
  36791. } else {
  36792. if (yych <= '\r') { gotoCase = 87; continue; };
  36793. if (yych == '\'') { gotoCase = 93; continue; };
  36794. { gotoCase = 94; continue; };
  36795. }
  36796.  
  36797. case this.case_TAG:
  36798. yych = this._charAt(cursor);
  36799. if (yych <= '&') {
  36800. if (yych <= '\r') {
  36801. if (yych == '\n') { gotoCase = 100; continue; };
  36802. if (yych >= '\r') { gotoCase = 100; continue; };
  36803. } else {
  36804. if (yych <= ' ') {
  36805. if (yych >= ' ') { gotoCase = 100; continue; };
  36806. } else {
  36807. if (yych == '"') { gotoCase = 102; continue; };
  36808. }
  36809. }
  36810. } else {
  36811. if (yych <= '>') {
  36812. if (yych <= ';') {
  36813. if (yych <= '\'') { gotoCase = 103; continue; };
  36814. } else {
  36815. if (yych <= '<') { gotoCase = 100; continue; };
  36816. if (yych <= '=') { gotoCase = 104; continue; };
  36817. { gotoCase = 106; continue; };
  36818. }
  36819. } else {
  36820. if (yych <= '[') {
  36821. if (yych >= '[') { gotoCase = 100; continue; };
  36822. } else {
  36823. if (yych == ']') { gotoCase = 100; continue; };
  36824. }
  36825. }
  36826. }
  36827. ++cursor;
  36828. yych = this._charAt(cursor);
  36829. { gotoCase = 119; continue; };
  36830. case 99:
  36831. {
  36832. if (this._condition.parseCondition === this._parseConditions.SCRIPT || this._condition.parseCondition === this._parseConditions.STYLE) {
  36833.  
  36834. this.tokenType = null;
  36835. return cursor;
  36836. }
  36837.  
  36838. if (this._condition.parseCondition === this._parseConditions.INITIAL) {
  36839. this.tokenType = "html-tag";
  36840. this._setExpectingAttribute();
  36841. var token = this._line.substring(cursorOnEnter, cursor);
  36842. if (token === "a")
  36843. this._condition.parseCondition |= this._parseConditions.A_NODE;
  36844. else if (this._condition.parseCondition & this._parseConditions.A_NODE)
  36845. this._condition.parseCondition ^= this._parseConditions.A_NODE;
  36846. } else if (this._isExpectingAttribute()) {
  36847. var token = this._line.substring(cursorOnEnter, cursor);
  36848. if (token === "href" || token === "src")
  36849. this._condition.parseCondition |= this._parseConditions.LINKIFY;
  36850. else if (this._condition.parseCondition |= this._parseConditions.LINKIFY)
  36851. this._condition.parseCondition ^= this._parseConditions.LINKIFY;
  36852. this.tokenType = "html-attribute-name";
  36853. } else if (this._isExpectingAttributeValue())
  36854. this.tokenType = this._attrValueTokenType();
  36855. else
  36856. this.tokenType = null;
  36857. return cursor;
  36858. }
  36859. case 100:
  36860. ++cursor;
  36861. { this.tokenType = null; return cursor; }
  36862. case 102:
  36863. yyaccept = 0;
  36864. yych = this._charAt(YYMARKER = ++cursor);
  36865. { gotoCase = 115; continue; };
  36866. case 103:
  36867. yyaccept = 0;
  36868. yych = this._charAt(YYMARKER = ++cursor);
  36869. { gotoCase = 109; continue; };
  36870. case 104:
  36871. ++cursor;
  36872. {
  36873. if (this._isExpectingAttribute())
  36874. this._setExpectingAttributeValue();
  36875. this.tokenType = null;
  36876. return cursor;
  36877. }
  36878. case 106:
  36879. ++cursor;
  36880. this.setLexCondition(this._lexConditions.INITIAL);
  36881. {
  36882. this.tokenType = "html-tag";
  36883. if (this._condition.parseCondition & this._parseConditions.SCRIPT) {
  36884. this.scriptStarted(cursor);
  36885.  
  36886. return cursor;
  36887. }
  36888.  
  36889. if (this._condition.parseCondition & this._parseConditions.STYLE) {
  36890. this.styleSheetStarted(cursor);
  36891.  
  36892. return cursor;
  36893. }
  36894.  
  36895. this._condition.parseCondition = this._parseConditions.INITIAL;
  36896. return cursor;
  36897. }
  36898. case 108:
  36899. ++cursor;
  36900. yych = this._charAt(cursor);
  36901. case 109:
  36902. if (yych <= '\f') {
  36903. if (yych != '\n') { gotoCase = 108; continue; };
  36904. } else {
  36905. if (yych <= '\r') { gotoCase = 110; continue; };
  36906. if (yych == '\'') { gotoCase = 112; continue; };
  36907. { gotoCase = 108; continue; };
  36908. }
  36909. case 110:
  36910. ++cursor;
  36911. this.setLexCondition(this._lexConditions.SSTRING);
  36912. { return this._stringToken(cursor); }
  36913. case 112:
  36914. ++cursor;
  36915. { return this._stringToken(cursor, true); }
  36916. case 114:
  36917. ++cursor;
  36918. yych = this._charAt(cursor);
  36919. case 115:
  36920. if (yych <= '\f') {
  36921. if (yych != '\n') { gotoCase = 114; continue; };
  36922. } else {
  36923. if (yych <= '\r') { gotoCase = 116; continue; };
  36924. if (yych == '"') { gotoCase = 112; continue; };
  36925. { gotoCase = 114; continue; };
  36926. }
  36927. case 116:
  36928. ++cursor;
  36929. this.setLexCondition(this._lexConditions.DSTRING);
  36930. { return this._stringToken(cursor); }
  36931. case 118:
  36932. ++cursor;
  36933. yych = this._charAt(cursor);
  36934. case 119:
  36935. if (yych <= '"') {
  36936. if (yych <= '\r') {
  36937. if (yych == '\n') { gotoCase = 99; continue; };
  36938. if (yych <= '\f') { gotoCase = 118; continue; };
  36939. { gotoCase = 99; continue; };
  36940. } else {
  36941. if (yych == ' ') { gotoCase = 99; continue; };
  36942. if (yych <= '!') { gotoCase = 118; continue; };
  36943. { gotoCase = 99; continue; };
  36944. }
  36945. } else {
  36946. if (yych <= '>') {
  36947. if (yych == '\'') { gotoCase = 99; continue; };
  36948. if (yych <= ';') { gotoCase = 118; continue; };
  36949. { gotoCase = 99; continue; };
  36950. } else {
  36951. if (yych <= '[') {
  36952. if (yych <= 'Z') { gotoCase = 118; continue; };
  36953. { gotoCase = 99; continue; };
  36954. } else {
  36955. if (yych == ']') { gotoCase = 99; continue; };
  36956. { gotoCase = 118; continue; };
  36957. }
  36958. }
  36959. }
  36960. }
  36961.  
  36962. }
  36963. },
  36964.  
  36965. __proto__: WebInspector.SourceTokenizer.prototype
  36966. }
  36967.  
  36968.  
  36969.  
  36970.  
  36971.  
  36972.  
  36973.  
  36974.  
  36975.  
  36976. WebInspector.SourceJavaScriptTokenizer = function()
  36977. {
  36978. WebInspector.SourceTokenizer.call(this);
  36979.  
  36980. this._lexConditions = {
  36981. DIV: 0,
  36982. NODIV: 1,
  36983. COMMENT: 2,
  36984. DSTRING: 3,
  36985. SSTRING: 4,
  36986. REGEX: 5
  36987. };
  36988.  
  36989. this.case_DIV = 1000;
  36990. this.case_NODIV = 1001;
  36991. this.case_COMMENT = 1002;
  36992. this.case_DSTRING = 1003;
  36993. this.case_SSTRING = 1004;
  36994. this.case_REGEX = 1005;
  36995.  
  36996. this.condition = this.createInitialCondition();
  36997. }
  36998.  
  36999. WebInspector.SourceJavaScriptTokenizer.Keywords = [
  37000. "null", "true", "false", "break", "case", "catch", "const", "default", "finally", "for",
  37001. "instanceof", "new", "var", "continue", "function", "return", "void", "delete", "if",
  37002. "this", "do", "while", "else", "in", "switch", "throw", "try", "typeof", "debugger",
  37003. "class", "enum", "export", "extends", "import", "super", "get", "set", "with"
  37004. ].keySet();
  37005.  
  37006. WebInspector.SourceJavaScriptTokenizer.prototype = {
  37007. createInitialCondition: function()
  37008. {
  37009. return { lexCondition: this._lexConditions.NODIV };
  37010. },
  37011.  
  37012. nextToken: function(cursor)
  37013. {
  37014. var cursorOnEnter = cursor;
  37015. var gotoCase = 1;
  37016. var YYMARKER;
  37017. while (1) {
  37018. switch (gotoCase)
  37019.  
  37020.  
  37021. {
  37022. case 1: var yych;
  37023. var yyaccept = 0;
  37024. if (this.getLexCondition() < 3) {
  37025. if (this.getLexCondition() < 1) {
  37026. { gotoCase = this.case_DIV; continue; };
  37027. } else {
  37028. if (this.getLexCondition() < 2) {
  37029. { gotoCase = this.case_NODIV; continue; };
  37030. } else {
  37031. { gotoCase = this.case_COMMENT; continue; };
  37032. }
  37033. }
  37034. } else {
  37035. if (this.getLexCondition() < 4) {
  37036. { gotoCase = this.case_DSTRING; continue; };
  37037. } else {
  37038. if (this.getLexCondition() < 5) {
  37039. { gotoCase = this.case_SSTRING; continue; };
  37040. } else {
  37041. { gotoCase = this.case_REGEX; continue; };
  37042. }
  37043. }
  37044. }
  37045.  
  37046. case this.case_COMMENT:
  37047.  
  37048. yych = this._charAt(cursor);
  37049. if (yych <= '\f') {
  37050. if (yych == '\n') { gotoCase = 4; continue; };
  37051. { gotoCase = 3; continue; };
  37052. } else {
  37053. if (yych <= '\r') { gotoCase = 4; continue; };
  37054. if (yych == '*') { gotoCase = 6; continue; };
  37055. { gotoCase = 3; continue; };
  37056. }
  37057. case 2:
  37058. { this.tokenType = "javascript-comment"; return cursor; }
  37059. case 3:
  37060. yyaccept = 0;
  37061. yych = this._charAt(YYMARKER = ++cursor);
  37062. { gotoCase = 12; continue; };
  37063. case 4:
  37064. ++cursor;
  37065. { this.tokenType = null; return cursor; }
  37066. case 6:
  37067. yyaccept = 1;
  37068. yych = this._charAt(YYMARKER = ++cursor);
  37069. if (yych == '*') { gotoCase = 9; continue; };
  37070. if (yych != '/') { gotoCase = 11; continue; };
  37071. case 7:
  37072. ++cursor;
  37073. this.setLexCondition(this._lexConditions.NODIV);
  37074. { this.tokenType = "javascript-comment"; return cursor; }
  37075. case 9:
  37076. ++cursor;
  37077. yych = this._charAt(cursor);
  37078. if (yych == '*') { gotoCase = 9; continue; };
  37079. if (yych == '/') { gotoCase = 7; continue; };
  37080. case 11:
  37081. yyaccept = 0;
  37082. YYMARKER = ++cursor;
  37083. yych = this._charAt(cursor);
  37084. case 12:
  37085. if (yych <= '\f') {
  37086. if (yych == '\n') { gotoCase = 2; continue; };
  37087. { gotoCase = 11; continue; };
  37088. } else {
  37089. if (yych <= '\r') { gotoCase = 2; continue; };
  37090. if (yych == '*') { gotoCase = 9; continue; };
  37091. { gotoCase = 11; continue; };
  37092. }
  37093.  
  37094. case this.case_DIV:
  37095. yych = this._charAt(cursor);
  37096. if (yych <= '9') {
  37097. if (yych <= '(') {
  37098. if (yych <= '#') {
  37099. if (yych <= ' ') { gotoCase = 15; continue; };
  37100. if (yych <= '!') { gotoCase = 17; continue; };
  37101. if (yych <= '"') { gotoCase = 19; continue; };
  37102. } else {
  37103. if (yych <= '%') {
  37104. if (yych <= '$') { gotoCase = 20; continue; };
  37105. { gotoCase = 22; continue; };
  37106. } else {
  37107. if (yych <= '&') { gotoCase = 23; continue; };
  37108. if (yych <= '\'') { gotoCase = 24; continue; };
  37109. { gotoCase = 25; continue; };
  37110. }
  37111. }
  37112. } else {
  37113. if (yych <= ',') {
  37114. if (yych <= ')') { gotoCase = 26; continue; };
  37115. if (yych <= '*') { gotoCase = 28; continue; };
  37116. if (yych <= '+') { gotoCase = 29; continue; };
  37117. { gotoCase = 25; continue; };
  37118. } else {
  37119. if (yych <= '.') {
  37120. if (yych <= '-') { gotoCase = 30; continue; };
  37121. { gotoCase = 31; continue; };
  37122. } else {
  37123. if (yych <= '/') { gotoCase = 32; continue; };
  37124. if (yych <= '0') { gotoCase = 34; continue; };
  37125. { gotoCase = 36; continue; };
  37126. }
  37127. }
  37128. }
  37129. } else {
  37130. if (yych <= '\\') {
  37131. if (yych <= '>') {
  37132. if (yych <= ';') { gotoCase = 25; continue; };
  37133. if (yych <= '<') { gotoCase = 37; continue; };
  37134. if (yych <= '=') { gotoCase = 38; continue; };
  37135. { gotoCase = 39; continue; };
  37136. } else {
  37137. if (yych <= '@') {
  37138. if (yych <= '?') { gotoCase = 25; continue; };
  37139. } else {
  37140. if (yych <= 'Z') { gotoCase = 20; continue; };
  37141. if (yych <= '[') { gotoCase = 25; continue; };
  37142. { gotoCase = 40; continue; };
  37143. }
  37144. }
  37145. } else {
  37146. if (yych <= 'z') {
  37147. if (yych <= '^') {
  37148. if (yych <= ']') { gotoCase = 25; continue; };
  37149. { gotoCase = 41; continue; };
  37150. } else {
  37151. if (yych != '`') { gotoCase = 20; continue; };
  37152. }
  37153. } else {
  37154. if (yych <= '|') {
  37155. if (yych <= '{') { gotoCase = 25; continue; };
  37156. { gotoCase = 42; continue; };
  37157. } else {
  37158. if (yych <= '~') { gotoCase = 25; continue; };
  37159. if (yych >= 0x80) { gotoCase = 20; continue; };
  37160. }
  37161. }
  37162. }
  37163. }
  37164. case 15:
  37165. ++cursor;
  37166. case 16:
  37167. { this.tokenType = null; return cursor; }
  37168. case 17:
  37169. ++cursor;
  37170. if ((yych = this._charAt(cursor)) == '=') { gotoCase = 115; continue; };
  37171. case 18:
  37172. this.setLexCondition(this._lexConditions.NODIV);
  37173. {
  37174. var token = this._line.charAt(cursorOnEnter);
  37175. if (token === "{")
  37176. this.tokenType = "block-start";
  37177. else if (token === "}")
  37178. this.tokenType = "block-end";
  37179. else this.tokenType = null;
  37180. return cursor;
  37181. }
  37182. case 19:
  37183. yyaccept = 0;
  37184. yych = this._charAt(YYMARKER = ++cursor);
  37185. if (yych == '\n') { gotoCase = 16; continue; };
  37186. if (yych == '\r') { gotoCase = 16; continue; };
  37187. { gotoCase = 107; continue; };
  37188. case 20:
  37189. yyaccept = 1;
  37190. yych = this._charAt(YYMARKER = ++cursor);
  37191. { gotoCase = 50; continue; };
  37192. case 21:
  37193. {
  37194. var token = this._line.substring(cursorOnEnter, cursor);
  37195. if (WebInspector.SourceJavaScriptTokenizer.Keywords[token] === true && token !== "__proto__")
  37196. this.tokenType = "javascript-keyword";
  37197. else
  37198. this.tokenType = "javascript-ident";
  37199. return cursor;
  37200. }
  37201. case 22:
  37202. yych = this._charAt(++cursor);
  37203. if (yych == '=') { gotoCase = 43; continue; };
  37204. { gotoCase = 18; continue; };
  37205. case 23:
  37206. yych = this._charAt(++cursor);
  37207. if (yych == '&') { gotoCase = 43; continue; };
  37208. if (yych == '=') { gotoCase = 43; continue; };
  37209. { gotoCase = 18; continue; };
  37210. case 24:
  37211. yyaccept = 0;
  37212. yych = this._charAt(YYMARKER = ++cursor);
  37213. if (yych == '\n') { gotoCase = 16; continue; };
  37214. if (yych == '\r') { gotoCase = 16; continue; };
  37215. { gotoCase = 96; continue; };
  37216. case 25:
  37217. yych = this._charAt(++cursor);
  37218. { gotoCase = 18; continue; };
  37219. case 26:
  37220. ++cursor;
  37221. { this.tokenType = null; return cursor; }
  37222. case 28:
  37223. yych = this._charAt(++cursor);
  37224. if (yych == '=') { gotoCase = 43; continue; };
  37225. { gotoCase = 18; continue; };
  37226. case 29:
  37227. yych = this._charAt(++cursor);
  37228. if (yych == '+') { gotoCase = 43; continue; };
  37229. if (yych == '=') { gotoCase = 43; continue; };
  37230. { gotoCase = 18; continue; };
  37231. case 30:
  37232. yych = this._charAt(++cursor);
  37233. if (yych == '-') { gotoCase = 43; continue; };
  37234. if (yych == '=') { gotoCase = 43; continue; };
  37235. { gotoCase = 18; continue; };
  37236. case 31:
  37237. yych = this._charAt(++cursor);
  37238. if (yych <= '/') { gotoCase = 18; continue; };
  37239. if (yych <= '9') { gotoCase = 89; continue; };
  37240. { gotoCase = 18; continue; };
  37241. case 32:
  37242. yyaccept = 2;
  37243. yych = this._charAt(YYMARKER = ++cursor);
  37244. if (yych <= '.') {
  37245. if (yych == '*') { gotoCase = 78; continue; };
  37246. } else {
  37247. if (yych <= '/') { gotoCase = 80; continue; };
  37248. if (yych == '=') { gotoCase = 77; continue; };
  37249. }
  37250. case 33:
  37251. this.setLexCondition(this._lexConditions.NODIV);
  37252. { this.tokenType = null; return cursor; }
  37253. case 34:
  37254. yyaccept = 3;
  37255. yych = this._charAt(YYMARKER = ++cursor);
  37256. if (yych <= 'E') {
  37257. if (yych <= '/') {
  37258. if (yych == '.') { gotoCase = 63; continue; };
  37259. } else {
  37260. if (yych <= '7') { gotoCase = 72; continue; };
  37261. if (yych >= 'E') { gotoCase = 62; continue; };
  37262. }
  37263. } else {
  37264. if (yych <= 'd') {
  37265. if (yych == 'X') { gotoCase = 74; continue; };
  37266. } else {
  37267. if (yych <= 'e') { gotoCase = 62; continue; };
  37268. if (yych == 'x') { gotoCase = 74; continue; };
  37269. }
  37270. }
  37271. case 35:
  37272. { this.tokenType = "javascript-number"; return cursor; }
  37273. case 36:
  37274. yyaccept = 3;
  37275. yych = this._charAt(YYMARKER = ++cursor);
  37276. if (yych <= '9') {
  37277. if (yych == '.') { gotoCase = 63; continue; };
  37278. if (yych <= '/') { gotoCase = 35; continue; };
  37279. { gotoCase = 60; continue; };
  37280. } else {
  37281. if (yych <= 'E') {
  37282. if (yych <= 'D') { gotoCase = 35; continue; };
  37283. { gotoCase = 62; continue; };
  37284. } else {
  37285. if (yych == 'e') { gotoCase = 62; continue; };
  37286. { gotoCase = 35; continue; };
  37287. }
  37288. }
  37289. case 37:
  37290. yych = this._charAt(++cursor);
  37291. if (yych <= ';') { gotoCase = 18; continue; };
  37292. if (yych <= '<') { gotoCase = 59; continue; };
  37293. if (yych <= '=') { gotoCase = 43; continue; };
  37294. { gotoCase = 18; continue; };
  37295. case 38:
  37296. yych = this._charAt(++cursor);
  37297. if (yych == '=') { gotoCase = 58; continue; };
  37298. { gotoCase = 18; continue; };
  37299. case 39:
  37300. yych = this._charAt(++cursor);
  37301. if (yych <= '<') { gotoCase = 18; continue; };
  37302. if (yych <= '=') { gotoCase = 43; continue; };
  37303. if (yych <= '>') { gotoCase = 56; continue; };
  37304. { gotoCase = 18; continue; };
  37305. case 40:
  37306. yyaccept = 0;
  37307. yych = this._charAt(YYMARKER = ++cursor);
  37308. if (yych == 'u') { gotoCase = 44; continue; };
  37309. { gotoCase = 16; continue; };
  37310. case 41:
  37311. yych = this._charAt(++cursor);
  37312. if (yych == '=') { gotoCase = 43; continue; };
  37313. { gotoCase = 18; continue; };
  37314. case 42:
  37315. yych = this._charAt(++cursor);
  37316. if (yych == '=') { gotoCase = 43; continue; };
  37317. if (yych != '|') { gotoCase = 18; continue; };
  37318. case 43:
  37319. yych = this._charAt(++cursor);
  37320. { gotoCase = 18; continue; };
  37321. case 44:
  37322. yych = this._charAt(++cursor);
  37323. if (yych <= '@') {
  37324. if (yych <= '/') { gotoCase = 45; continue; };
  37325. if (yych <= '9') { gotoCase = 46; continue; };
  37326. } else {
  37327. if (yych <= 'F') { gotoCase = 46; continue; };
  37328. if (yych <= '`') { gotoCase = 45; continue; };
  37329. if (yych <= 'f') { gotoCase = 46; continue; };
  37330. }
  37331. case 45:
  37332. cursor = YYMARKER;
  37333. if (yyaccept <= 1) {
  37334. if (yyaccept <= 0) {
  37335. { gotoCase = 16; continue; };
  37336. } else {
  37337. { gotoCase = 21; continue; };
  37338. }
  37339. } else {
  37340. if (yyaccept <= 2) {
  37341. { gotoCase = 33; continue; };
  37342. } else {
  37343. { gotoCase = 35; continue; };
  37344. }
  37345. }
  37346. case 46:
  37347. yych = this._charAt(++cursor);
  37348. if (yych <= '@') {
  37349. if (yych <= '/') { gotoCase = 45; continue; };
  37350. if (yych >= ':') { gotoCase = 45; continue; };
  37351. } else {
  37352. if (yych <= 'F') { gotoCase = 47; continue; };
  37353. if (yych <= '`') { gotoCase = 45; continue; };
  37354. if (yych >= 'g') { gotoCase = 45; continue; };
  37355. }
  37356. case 47:
  37357. yych = this._charAt(++cursor);
  37358. if (yych <= '@') {
  37359. if (yych <= '/') { gotoCase = 45; continue; };
  37360. if (yych >= ':') { gotoCase = 45; continue; };
  37361. } else {
  37362. if (yych <= 'F') { gotoCase = 48; continue; };
  37363. if (yych <= '`') { gotoCase = 45; continue; };
  37364. if (yych >= 'g') { gotoCase = 45; continue; };
  37365. }
  37366. case 48:
  37367. yych = this._charAt(++cursor);
  37368. if (yych <= '@') {
  37369. if (yych <= '/') { gotoCase = 45; continue; };
  37370. if (yych >= ':') { gotoCase = 45; continue; };
  37371. } else {
  37372. if (yych <= 'F') { gotoCase = 49; continue; };
  37373. if (yych <= '`') { gotoCase = 45; continue; };
  37374. if (yych >= 'g') { gotoCase = 45; continue; };
  37375. }
  37376. case 49:
  37377. yyaccept = 1;
  37378. YYMARKER = ++cursor;
  37379. yych = this._charAt(cursor);
  37380. case 50:
  37381. if (yych <= '[') {
  37382. if (yych <= '/') {
  37383. if (yych == '$') { gotoCase = 49; continue; };
  37384. { gotoCase = 21; continue; };
  37385. } else {
  37386. if (yych <= '9') { gotoCase = 49; continue; };
  37387. if (yych <= '@') { gotoCase = 21; continue; };
  37388. if (yych <= 'Z') { gotoCase = 49; continue; };
  37389. { gotoCase = 21; continue; };
  37390. }
  37391. } else {
  37392. if (yych <= '_') {
  37393. if (yych <= '\\') { gotoCase = 51; continue; };
  37394. if (yych <= '^') { gotoCase = 21; continue; };
  37395. { gotoCase = 49; continue; };
  37396. } else {
  37397. if (yych <= '`') { gotoCase = 21; continue; };
  37398. if (yych <= 'z') { gotoCase = 49; continue; };
  37399. if (yych <= String.fromCharCode(0x7F)) { gotoCase = 21; continue; };
  37400. { gotoCase = 49; continue; };
  37401. }
  37402. }
  37403. case 51:
  37404. ++cursor;
  37405. yych = this._charAt(cursor);
  37406. if (yych != 'u') { gotoCase = 45; continue; };
  37407. ++cursor;
  37408. yych = this._charAt(cursor);
  37409. if (yych <= '@') {
  37410. if (yych <= '/') { gotoCase = 45; continue; };
  37411. if (yych >= ':') { gotoCase = 45; continue; };
  37412. } else {
  37413. if (yych <= 'F') { gotoCase = 53; continue; };
  37414. if (yych <= '`') { gotoCase = 45; continue; };
  37415. if (yych >= 'g') { gotoCase = 45; continue; };
  37416. }
  37417. case 53:
  37418. ++cursor;
  37419. yych = this._charAt(cursor);
  37420. if (yych <= '@') {
  37421. if (yych <= '/') { gotoCase = 45; continue; };
  37422. if (yych >= ':') { gotoCase = 45; continue; };
  37423. } else {
  37424. if (yych <= 'F') { gotoCase = 54; continue; };
  37425. if (yych <= '`') { gotoCase = 45; continue; };
  37426. if (yych >= 'g') { gotoCase = 45; continue; };
  37427. }
  37428. case 54:
  37429. ++cursor;
  37430. yych = this._charAt(cursor);
  37431. if (yych <= '@') {
  37432. if (yych <= '/') { gotoCase = 45; continue; };
  37433. if (yych >= ':') { gotoCase = 45; continue; };
  37434. } else {
  37435. if (yych <= 'F') { gotoCase = 55; continue; };
  37436. if (yych <= '`') { gotoCase = 45; continue; };
  37437. if (yych >= 'g') { gotoCase = 45; continue; };
  37438. }
  37439. case 55:
  37440. ++cursor;
  37441. yych = this._charAt(cursor);
  37442. if (yych <= '@') {
  37443. if (yych <= '/') { gotoCase = 45; continue; };
  37444. if (yych <= '9') { gotoCase = 49; continue; };
  37445. { gotoCase = 45; continue; };
  37446. } else {
  37447. if (yych <= 'F') { gotoCase = 49; continue; };
  37448. if (yych <= '`') { gotoCase = 45; continue; };
  37449. if (yych <= 'f') { gotoCase = 49; continue; };
  37450. { gotoCase = 45; continue; };
  37451. }
  37452. case 56:
  37453. yych = this._charAt(++cursor);
  37454. if (yych <= '<') { gotoCase = 18; continue; };
  37455. if (yych <= '=') { gotoCase = 43; continue; };
  37456. if (yych >= '?') { gotoCase = 18; continue; };
  37457. yych = this._charAt(++cursor);
  37458. if (yych == '=') { gotoCase = 43; continue; };
  37459. { gotoCase = 18; continue; };
  37460. case 58:
  37461. yych = this._charAt(++cursor);
  37462. if (yych == '=') { gotoCase = 43; continue; };
  37463. { gotoCase = 18; continue; };
  37464. case 59:
  37465. yych = this._charAt(++cursor);
  37466. if (yych == '=') { gotoCase = 43; continue; };
  37467. { gotoCase = 18; continue; };
  37468. case 60:
  37469. yyaccept = 3;
  37470. YYMARKER = ++cursor;
  37471. yych = this._charAt(cursor);
  37472. if (yych <= '9') {
  37473. if (yych == '.') { gotoCase = 63; continue; };
  37474. if (yych <= '/') { gotoCase = 35; continue; };
  37475. { gotoCase = 60; continue; };
  37476. } else {
  37477. if (yych <= 'E') {
  37478. if (yych <= 'D') { gotoCase = 35; continue; };
  37479. } else {
  37480. if (yych != 'e') { gotoCase = 35; continue; };
  37481. }
  37482. }
  37483. case 62:
  37484. yych = this._charAt(++cursor);
  37485. if (yych <= ',') {
  37486. if (yych == '+') { gotoCase = 69; continue; };
  37487. { gotoCase = 45; continue; };
  37488. } else {
  37489. if (yych <= '-') { gotoCase = 69; continue; };
  37490. if (yych <= '/') { gotoCase = 45; continue; };
  37491. if (yych <= '9') { gotoCase = 70; continue; };
  37492. { gotoCase = 45; continue; };
  37493. }
  37494. case 63:
  37495. yyaccept = 3;
  37496. YYMARKER = ++cursor;
  37497. yych = this._charAt(cursor);
  37498. if (yych <= 'D') {
  37499. if (yych <= '/') { gotoCase = 35; continue; };
  37500. if (yych <= '9') { gotoCase = 63; continue; };
  37501. { gotoCase = 35; continue; };
  37502. } else {
  37503. if (yych <= 'E') { gotoCase = 65; continue; };
  37504. if (yych != 'e') { gotoCase = 35; continue; };
  37505. }
  37506. case 65:
  37507. yych = this._charAt(++cursor);
  37508. if (yych <= ',') {
  37509. if (yych != '+') { gotoCase = 45; continue; };
  37510. } else {
  37511. if (yych <= '-') { gotoCase = 66; continue; };
  37512. if (yych <= '/') { gotoCase = 45; continue; };
  37513. if (yych <= '9') { gotoCase = 67; continue; };
  37514. { gotoCase = 45; continue; };
  37515. }
  37516. case 66:
  37517. yych = this._charAt(++cursor);
  37518. if (yych <= '/') { gotoCase = 45; continue; };
  37519. if (yych >= ':') { gotoCase = 45; continue; };
  37520. case 67:
  37521. ++cursor;
  37522. yych = this._charAt(cursor);
  37523. if (yych <= '/') { gotoCase = 35; continue; };
  37524. if (yych <= '9') { gotoCase = 67; continue; };
  37525. { gotoCase = 35; continue; };
  37526. case 69:
  37527. yych = this._charAt(++cursor);
  37528. if (yych <= '/') { gotoCase = 45; continue; };
  37529. if (yych >= ':') { gotoCase = 45; continue; };
  37530. case 70:
  37531. ++cursor;
  37532. yych = this._charAt(cursor);
  37533. if (yych <= '/') { gotoCase = 35; continue; };
  37534. if (yych <= '9') { gotoCase = 70; continue; };
  37535. { gotoCase = 35; continue; };
  37536. case 72:
  37537. ++cursor;
  37538. yych = this._charAt(cursor);
  37539. if (yych <= '/') { gotoCase = 35; continue; };
  37540. if (yych <= '7') { gotoCase = 72; continue; };
  37541. { gotoCase = 35; continue; };
  37542. case 74:
  37543. yych = this._charAt(++cursor);
  37544. if (yych <= '@') {
  37545. if (yych <= '/') { gotoCase = 45; continue; };
  37546. if (yych >= ':') { gotoCase = 45; continue; };
  37547. } else {
  37548. if (yych <= 'F') { gotoCase = 75; continue; };
  37549. if (yych <= '`') { gotoCase = 45; continue; };
  37550. if (yych >= 'g') { gotoCase = 45; continue; };
  37551. }
  37552. case 75:
  37553. ++cursor;
  37554. yych = this._charAt(cursor);
  37555. if (yych <= '@') {
  37556. if (yych <= '/') { gotoCase = 35; continue; };
  37557. if (yych <= '9') { gotoCase = 75; continue; };
  37558. { gotoCase = 35; continue; };
  37559. } else {
  37560. if (yych <= 'F') { gotoCase = 75; continue; };
  37561. if (yych <= '`') { gotoCase = 35; continue; };
  37562. if (yych <= 'f') { gotoCase = 75; continue; };
  37563. { gotoCase = 35; continue; };
  37564. }
  37565. case 77:
  37566. yych = this._charAt(++cursor);
  37567. { gotoCase = 33; continue; };
  37568. case 78:
  37569. ++cursor;
  37570. yych = this._charAt(cursor);
  37571. if (yych <= '\f') {
  37572. if (yych == '\n') { gotoCase = 85; continue; };
  37573. { gotoCase = 78; continue; };
  37574. } else {
  37575. if (yych <= '\r') { gotoCase = 85; continue; };
  37576. if (yych == '*') { gotoCase = 83; continue; };
  37577. { gotoCase = 78; continue; };
  37578. }
  37579. case 80:
  37580. ++cursor;
  37581. yych = this._charAt(cursor);
  37582. if (yych == '\n') { gotoCase = 82; continue; };
  37583. if (yych != '\r') { gotoCase = 80; continue; };
  37584. case 82:
  37585. { this.tokenType = "javascript-comment"; return cursor; }
  37586. case 83:
  37587. ++cursor;
  37588. yych = this._charAt(cursor);
  37589. if (yych == '*') { gotoCase = 83; continue; };
  37590. if (yych == '/') { gotoCase = 87; continue; };
  37591. { gotoCase = 78; continue; };
  37592. case 85:
  37593. ++cursor;
  37594. this.setLexCondition(this._lexConditions.COMMENT);
  37595. { this.tokenType = "javascript-comment"; return cursor; }
  37596. case 87:
  37597. ++cursor;
  37598. { this.tokenType = "javascript-comment"; return cursor; }
  37599. case 89:
  37600. yyaccept = 3;
  37601. YYMARKER = ++cursor;
  37602. yych = this._charAt(cursor);
  37603. if (yych <= 'D') {
  37604. if (yych <= '/') { gotoCase = 35; continue; };
  37605. if (yych <= '9') { gotoCase = 89; continue; };
  37606. { gotoCase = 35; continue; };
  37607. } else {
  37608. if (yych <= 'E') { gotoCase = 91; continue; };
  37609. if (yych != 'e') { gotoCase = 35; continue; };
  37610. }
  37611. case 91:
  37612. yych = this._charAt(++cursor);
  37613. if (yych <= ',') {
  37614. if (yych != '+') { gotoCase = 45; continue; };
  37615. } else {
  37616. if (yych <= '-') { gotoCase = 92; continue; };
  37617. if (yych <= '/') { gotoCase = 45; continue; };
  37618. if (yych <= '9') { gotoCase = 93; continue; };
  37619. { gotoCase = 45; continue; };
  37620. }
  37621. case 92:
  37622. yych = this._charAt(++cursor);
  37623. if (yych <= '/') { gotoCase = 45; continue; };
  37624. if (yych >= ':') { gotoCase = 45; continue; };
  37625. case 93:
  37626. ++cursor;
  37627. yych = this._charAt(cursor);
  37628. if (yych <= '/') { gotoCase = 35; continue; };
  37629. if (yych <= '9') { gotoCase = 93; continue; };
  37630. { gotoCase = 35; continue; };
  37631. case 95:
  37632. ++cursor;
  37633. yych = this._charAt(cursor);
  37634. case 96:
  37635. if (yych <= '\r') {
  37636. if (yych == '\n') { gotoCase = 45; continue; };
  37637. if (yych <= '\f') { gotoCase = 95; continue; };
  37638. { gotoCase = 45; continue; };
  37639. } else {
  37640. if (yych <= '\'') {
  37641. if (yych <= '&') { gotoCase = 95; continue; };
  37642. { gotoCase = 98; continue; };
  37643. } else {
  37644. if (yych != '\\') { gotoCase = 95; continue; };
  37645. }
  37646. }
  37647. ++cursor;
  37648. yych = this._charAt(cursor);
  37649. if (yych <= 'a') {
  37650. if (yych <= '!') {
  37651. if (yych <= '\n') {
  37652. if (yych <= '\t') { gotoCase = 45; continue; };
  37653. { gotoCase = 101; continue; };
  37654. } else {
  37655. if (yych == '\r') { gotoCase = 101; continue; };
  37656. { gotoCase = 45; continue; };
  37657. }
  37658. } else {
  37659. if (yych <= '\'') {
  37660. if (yych <= '"') { gotoCase = 95; continue; };
  37661. if (yych <= '&') { gotoCase = 45; continue; };
  37662. { gotoCase = 95; continue; };
  37663. } else {
  37664. if (yych == '\\') { gotoCase = 95; continue; };
  37665. { gotoCase = 45; continue; };
  37666. }
  37667. }
  37668. } else {
  37669. if (yych <= 'q') {
  37670. if (yych <= 'f') {
  37671. if (yych <= 'b') { gotoCase = 95; continue; };
  37672. if (yych <= 'e') { gotoCase = 45; continue; };
  37673. { gotoCase = 95; continue; };
  37674. } else {
  37675. if (yych == 'n') { gotoCase = 95; continue; };
  37676. { gotoCase = 45; continue; };
  37677. }
  37678. } else {
  37679. if (yych <= 't') {
  37680. if (yych == 's') { gotoCase = 45; continue; };
  37681. { gotoCase = 95; continue; };
  37682. } else {
  37683. if (yych <= 'u') { gotoCase = 100; continue; };
  37684. if (yych <= 'v') { gotoCase = 95; continue; };
  37685. { gotoCase = 45; continue; };
  37686. }
  37687. }
  37688. }
  37689. case 98:
  37690. ++cursor;
  37691. { this.tokenType = "javascript-string"; return cursor; }
  37692. case 100:
  37693. ++cursor;
  37694. yych = this._charAt(cursor);
  37695. if (yych <= '@') {
  37696. if (yych <= '/') { gotoCase = 45; continue; };
  37697. if (yych <= '9') { gotoCase = 103; continue; };
  37698. { gotoCase = 45; continue; };
  37699. } else {
  37700. if (yych <= 'F') { gotoCase = 103; continue; };
  37701. if (yych <= '`') { gotoCase = 45; continue; };
  37702. if (yych <= 'f') { gotoCase = 103; continue; };
  37703. { gotoCase = 45; continue; };
  37704. }
  37705. case 101:
  37706. ++cursor;
  37707. this.setLexCondition(this._lexConditions.SSTRING);
  37708. { this.tokenType = "javascript-string"; return cursor; }
  37709. case 103:
  37710. ++cursor;
  37711. yych = this._charAt(cursor);
  37712. if (yych <= '@') {
  37713. if (yych <= '/') { gotoCase = 45; continue; };
  37714. if (yych >= ':') { gotoCase = 45; continue; };
  37715. } else {
  37716. if (yych <= 'F') { gotoCase = 104; continue; };
  37717. if (yych <= '`') { gotoCase = 45; continue; };
  37718. if (yych >= 'g') { gotoCase = 45; continue; };
  37719. }
  37720. case 104:
  37721. ++cursor;
  37722. yych = this._charAt(cursor);
  37723. if (yych <= '@') {
  37724. if (yych <= '/') { gotoCase = 45; continue; };
  37725. if (yych >= ':') { gotoCase = 45; continue; };
  37726. } else {
  37727. if (yych <= 'F') { gotoCase = 105; continue; };
  37728. if (yych <= '`') { gotoCase = 45; continue; };
  37729. if (yych >= 'g') { gotoCase = 45; continue; };
  37730. }
  37731. case 105:
  37732. ++cursor;
  37733. yych = this._charAt(cursor);
  37734. if (yych <= '@') {
  37735. if (yych <= '/') { gotoCase = 45; continue; };
  37736. if (yych <= '9') { gotoCase = 95; continue; };
  37737. { gotoCase = 45; continue; };
  37738. } else {
  37739. if (yych <= 'F') { gotoCase = 95; continue; };
  37740. if (yych <= '`') { gotoCase = 45; continue; };
  37741. if (yych <= 'f') { gotoCase = 95; continue; };
  37742. { gotoCase = 45; continue; };
  37743. }
  37744. case 106:
  37745. ++cursor;
  37746. yych = this._charAt(cursor);
  37747. case 107:
  37748. if (yych <= '\r') {
  37749. if (yych == '\n') { gotoCase = 45; continue; };
  37750. if (yych <= '\f') { gotoCase = 106; continue; };
  37751. { gotoCase = 45; continue; };
  37752. } else {
  37753. if (yych <= '"') {
  37754. if (yych <= '!') { gotoCase = 106; continue; };
  37755. { gotoCase = 98; continue; };
  37756. } else {
  37757. if (yych != '\\') { gotoCase = 106; continue; };
  37758. }
  37759. }
  37760. ++cursor;
  37761. yych = this._charAt(cursor);
  37762. if (yych <= 'a') {
  37763. if (yych <= '!') {
  37764. if (yych <= '\n') {
  37765. if (yych <= '\t') { gotoCase = 45; continue; };
  37766. { gotoCase = 110; continue; };
  37767. } else {
  37768. if (yych == '\r') { gotoCase = 110; continue; };
  37769. { gotoCase = 45; continue; };
  37770. }
  37771. } else {
  37772. if (yych <= '\'') {
  37773. if (yych <= '"') { gotoCase = 106; continue; };
  37774. if (yych <= '&') { gotoCase = 45; continue; };
  37775. { gotoCase = 106; continue; };
  37776. } else {
  37777. if (yych == '\\') { gotoCase = 106; continue; };
  37778. { gotoCase = 45; continue; };
  37779. }
  37780. }
  37781. } else {
  37782. if (yych <= 'q') {
  37783. if (yych <= 'f') {
  37784. if (yych <= 'b') { gotoCase = 106; continue; };
  37785. if (yych <= 'e') { gotoCase = 45; continue; };
  37786. { gotoCase = 106; continue; };
  37787. } else {
  37788. if (yych == 'n') { gotoCase = 106; continue; };
  37789. { gotoCase = 45; continue; };
  37790. }
  37791. } else {
  37792. if (yych <= 't') {
  37793. if (yych == 's') { gotoCase = 45; continue; };
  37794. { gotoCase = 106; continue; };
  37795. } else {
  37796. if (yych <= 'u') { gotoCase = 109; continue; };
  37797. if (yych <= 'v') { gotoCase = 106; continue; };
  37798. { gotoCase = 45; continue; };
  37799. }
  37800. }
  37801. }
  37802. case 109:
  37803. ++cursor;
  37804. yych = this._charAt(cursor);
  37805. if (yych <= '@') {
  37806. if (yych <= '/') { gotoCase = 45; continue; };
  37807. if (yych <= '9') { gotoCase = 112; continue; };
  37808. { gotoCase = 45; continue; };
  37809. } else {
  37810. if (yych <= 'F') { gotoCase = 112; continue; };
  37811. if (yych <= '`') { gotoCase = 45; continue; };
  37812. if (yych <= 'f') { gotoCase = 112; continue; };
  37813. { gotoCase = 45; continue; };
  37814. }
  37815. case 110:
  37816. ++cursor;
  37817. this.setLexCondition(this._lexConditions.DSTRING);
  37818. { this.tokenType = "javascript-string"; return cursor; }
  37819. case 112:
  37820. ++cursor;
  37821. yych = this._charAt(cursor);
  37822. if (yych <= '@') {
  37823. if (yych <= '/') { gotoCase = 45; continue; };
  37824. if (yych >= ':') { gotoCase = 45; continue; };
  37825. } else {
  37826. if (yych <= 'F') { gotoCase = 113; continue; };
  37827. if (yych <= '`') { gotoCase = 45; continue; };
  37828. if (yych >= 'g') { gotoCase = 45; continue; };
  37829. }
  37830. case 113:
  37831. ++cursor;
  37832. yych = this._charAt(cursor);
  37833. if (yych <= '@') {
  37834. if (yych <= '/') { gotoCase = 45; continue; };
  37835. if (yych >= ':') { gotoCase = 45; continue; };
  37836. } else {
  37837. if (yych <= 'F') { gotoCase = 114; continue; };
  37838. if (yych <= '`') { gotoCase = 45; continue; };
  37839. if (yych >= 'g') { gotoCase = 45; continue; };
  37840. }
  37841. case 114:
  37842. ++cursor;
  37843. yych = this._charAt(cursor);
  37844. if (yych <= '@') {
  37845. if (yych <= '/') { gotoCase = 45; continue; };
  37846. if (yych <= '9') { gotoCase = 106; continue; };
  37847. { gotoCase = 45; continue; };
  37848. } else {
  37849. if (yych <= 'F') { gotoCase = 106; continue; };
  37850. if (yych <= '`') { gotoCase = 45; continue; };
  37851. if (yych <= 'f') { gotoCase = 106; continue; };
  37852. { gotoCase = 45; continue; };
  37853. }
  37854. case 115:
  37855. ++cursor;
  37856. if ((yych = this._charAt(cursor)) == '=') { gotoCase = 43; continue; };
  37857. { gotoCase = 18; continue; };
  37858.  
  37859. case this.case_DSTRING:
  37860. yych = this._charAt(cursor);
  37861. if (yych <= '\r') {
  37862. if (yych == '\n') { gotoCase = 120; continue; };
  37863. if (yych <= '\f') { gotoCase = 119; continue; };
  37864. { gotoCase = 120; continue; };
  37865. } else {
  37866. if (yych <= '"') {
  37867. if (yych <= '!') { gotoCase = 119; continue; };
  37868. { gotoCase = 122; continue; };
  37869. } else {
  37870. if (yych == '\\') { gotoCase = 124; continue; };
  37871. { gotoCase = 119; continue; };
  37872. }
  37873. }
  37874. case 118:
  37875. { this.tokenType = "javascript-string"; return cursor; }
  37876. case 119:
  37877. yyaccept = 0;
  37878. yych = this._charAt(YYMARKER = ++cursor);
  37879. { gotoCase = 126; continue; };
  37880. case 120:
  37881. ++cursor;
  37882. case 121:
  37883. { this.tokenType = null; return cursor; }
  37884. case 122:
  37885. ++cursor;
  37886. case 123:
  37887. this.setLexCondition(this._lexConditions.NODIV);
  37888. { this.tokenType = "javascript-string"; return cursor; }
  37889. case 124:
  37890. yyaccept = 1;
  37891. yych = this._charAt(YYMARKER = ++cursor);
  37892. if (yych <= 'e') {
  37893. if (yych <= '\'') {
  37894. if (yych == '"') { gotoCase = 125; continue; };
  37895. if (yych <= '&') { gotoCase = 121; continue; };
  37896. } else {
  37897. if (yych <= '\\') {
  37898. if (yych <= '[') { gotoCase = 121; continue; };
  37899. } else {
  37900. if (yych != 'b') { gotoCase = 121; continue; };
  37901. }
  37902. }
  37903. } else {
  37904. if (yych <= 'r') {
  37905. if (yych <= 'm') {
  37906. if (yych >= 'g') { gotoCase = 121; continue; };
  37907. } else {
  37908. if (yych <= 'n') { gotoCase = 125; continue; };
  37909. if (yych <= 'q') { gotoCase = 121; continue; };
  37910. }
  37911. } else {
  37912. if (yych <= 't') {
  37913. if (yych <= 's') { gotoCase = 121; continue; };
  37914. } else {
  37915. if (yych <= 'u') { gotoCase = 127; continue; };
  37916. if (yych >= 'w') { gotoCase = 121; continue; };
  37917. }
  37918. }
  37919. }
  37920. case 125:
  37921. yyaccept = 0;
  37922. YYMARKER = ++cursor;
  37923. yych = this._charAt(cursor);
  37924. case 126:
  37925. if (yych <= '\r') {
  37926. if (yych == '\n') { gotoCase = 118; continue; };
  37927. if (yych <= '\f') { gotoCase = 125; continue; };
  37928. { gotoCase = 118; continue; };
  37929. } else {
  37930. if (yych <= '"') {
  37931. if (yych <= '!') { gotoCase = 125; continue; };
  37932. { gotoCase = 133; continue; };
  37933. } else {
  37934. if (yych == '\\') { gotoCase = 132; continue; };
  37935. { gotoCase = 125; continue; };
  37936. }
  37937. }
  37938. case 127:
  37939. ++cursor;
  37940. yych = this._charAt(cursor);
  37941. if (yych <= '@') {
  37942. if (yych <= '/') { gotoCase = 128; continue; };
  37943. if (yych <= '9') { gotoCase = 129; continue; };
  37944. } else {
  37945. if (yych <= 'F') { gotoCase = 129; continue; };
  37946. if (yych <= '`') { gotoCase = 128; continue; };
  37947. if (yych <= 'f') { gotoCase = 129; continue; };
  37948. }
  37949. case 128:
  37950. cursor = YYMARKER;
  37951. if (yyaccept <= 0) {
  37952. { gotoCase = 118; continue; };
  37953. } else {
  37954. { gotoCase = 121; continue; };
  37955. }
  37956. case 129:
  37957. ++cursor;
  37958. yych = this._charAt(cursor);
  37959. if (yych <= '@') {
  37960. if (yych <= '/') { gotoCase = 128; continue; };
  37961. if (yych >= ':') { gotoCase = 128; continue; };
  37962. } else {
  37963. if (yych <= 'F') { gotoCase = 130; continue; };
  37964. if (yych <= '`') { gotoCase = 128; continue; };
  37965. if (yych >= 'g') { gotoCase = 128; continue; };
  37966. }
  37967. case 130:
  37968. ++cursor;
  37969. yych = this._charAt(cursor);
  37970. if (yych <= '@') {
  37971. if (yych <= '/') { gotoCase = 128; continue; };
  37972. if (yych >= ':') { gotoCase = 128; continue; };
  37973. } else {
  37974. if (yych <= 'F') { gotoCase = 131; continue; };
  37975. if (yych <= '`') { gotoCase = 128; continue; };
  37976. if (yych >= 'g') { gotoCase = 128; continue; };
  37977. }
  37978. case 131:
  37979. ++cursor;
  37980. yych = this._charAt(cursor);
  37981. if (yych <= '@') {
  37982. if (yych <= '/') { gotoCase = 128; continue; };
  37983. if (yych <= '9') { gotoCase = 125; continue; };
  37984. { gotoCase = 128; continue; };
  37985. } else {
  37986. if (yych <= 'F') { gotoCase = 125; continue; };
  37987. if (yych <= '`') { gotoCase = 128; continue; };
  37988. if (yych <= 'f') { gotoCase = 125; continue; };
  37989. { gotoCase = 128; continue; };
  37990. }
  37991. case 132:
  37992. ++cursor;
  37993. yych = this._charAt(cursor);
  37994. if (yych <= 'e') {
  37995. if (yych <= '\'') {
  37996. if (yych == '"') { gotoCase = 125; continue; };
  37997. if (yych <= '&') { gotoCase = 128; continue; };
  37998. { gotoCase = 125; continue; };
  37999. } else {
  38000. if (yych <= '\\') {
  38001. if (yych <= '[') { gotoCase = 128; continue; };
  38002. { gotoCase = 125; continue; };
  38003. } else {
  38004. if (yych == 'b') { gotoCase = 125; continue; };
  38005. { gotoCase = 128; continue; };
  38006. }
  38007. }
  38008. } else {
  38009. if (yych <= 'r') {
  38010. if (yych <= 'm') {
  38011. if (yych <= 'f') { gotoCase = 125; continue; };
  38012. { gotoCase = 128; continue; };
  38013. } else {
  38014. if (yych <= 'n') { gotoCase = 125; continue; };
  38015. if (yych <= 'q') { gotoCase = 128; continue; };
  38016. { gotoCase = 125; continue; };
  38017. }
  38018. } else {
  38019. if (yych <= 't') {
  38020. if (yych <= 's') { gotoCase = 128; continue; };
  38021. { gotoCase = 125; continue; };
  38022. } else {
  38023. if (yych <= 'u') { gotoCase = 127; continue; };
  38024. if (yych <= 'v') { gotoCase = 125; continue; };
  38025. { gotoCase = 128; continue; };
  38026. }
  38027. }
  38028. }
  38029. case 133:
  38030. ++cursor;
  38031. yych = this._charAt(cursor);
  38032. { gotoCase = 123; continue; };
  38033.  
  38034. case this.case_NODIV:
  38035. yych = this._charAt(cursor);
  38036. if (yych <= '9') {
  38037. if (yych <= '(') {
  38038. if (yych <= '#') {
  38039. if (yych <= ' ') { gotoCase = 136; continue; };
  38040. if (yych <= '!') { gotoCase = 138; continue; };
  38041. if (yych <= '"') { gotoCase = 140; continue; };
  38042. } else {
  38043. if (yych <= '%') {
  38044. if (yych <= '$') { gotoCase = 141; continue; };
  38045. { gotoCase = 143; continue; };
  38046. } else {
  38047. if (yych <= '&') { gotoCase = 144; continue; };
  38048. if (yych <= '\'') { gotoCase = 145; continue; };
  38049. { gotoCase = 146; continue; };
  38050. }
  38051. }
  38052. } else {
  38053. if (yych <= ',') {
  38054. if (yych <= ')') { gotoCase = 147; continue; };
  38055. if (yych <= '*') { gotoCase = 149; continue; };
  38056. if (yych <= '+') { gotoCase = 150; continue; };
  38057. { gotoCase = 146; continue; };
  38058. } else {
  38059. if (yych <= '.') {
  38060. if (yych <= '-') { gotoCase = 151; continue; };
  38061. { gotoCase = 152; continue; };
  38062. } else {
  38063. if (yych <= '/') { gotoCase = 153; continue; };
  38064. if (yych <= '0') { gotoCase = 154; continue; };
  38065. { gotoCase = 156; continue; };
  38066. }
  38067. }
  38068. }
  38069. } else {
  38070. if (yych <= '\\') {
  38071. if (yych <= '>') {
  38072. if (yych <= ';') { gotoCase = 146; continue; };
  38073. if (yych <= '<') { gotoCase = 157; continue; };
  38074. if (yych <= '=') { gotoCase = 158; continue; };
  38075. { gotoCase = 159; continue; };
  38076. } else {
  38077. if (yych <= '@') {
  38078. if (yych <= '?') { gotoCase = 146; continue; };
  38079. } else {
  38080. if (yych <= 'Z') { gotoCase = 141; continue; };
  38081. if (yych <= '[') { gotoCase = 146; continue; };
  38082. { gotoCase = 160; continue; };
  38083. }
  38084. }
  38085. } else {
  38086. if (yych <= 'z') {
  38087. if (yych <= '^') {
  38088. if (yych <= ']') { gotoCase = 146; continue; };
  38089. { gotoCase = 161; continue; };
  38090. } else {
  38091. if (yych != '`') { gotoCase = 141; continue; };
  38092. }
  38093. } else {
  38094. if (yych <= '|') {
  38095. if (yych <= '{') { gotoCase = 146; continue; };
  38096. { gotoCase = 162; continue; };
  38097. } else {
  38098. if (yych <= '~') { gotoCase = 146; continue; };
  38099. if (yych >= 0x80) { gotoCase = 141; continue; };
  38100. }
  38101. }
  38102. }
  38103. }
  38104. case 136:
  38105. ++cursor;
  38106. case 137:
  38107. { this.tokenType = null; return cursor; }
  38108. case 138:
  38109. ++cursor;
  38110. if ((yych = this._charAt(cursor)) == '=') { gotoCase = 260; continue; };
  38111. case 139:
  38112. {
  38113. var token = this._line.charAt(cursorOnEnter);
  38114. if (token === "{")
  38115. this.tokenType = "block-start";
  38116. else if (token === "}")
  38117. this.tokenType = "block-end";
  38118. else this.tokenType = null;
  38119. return cursor;
  38120. }
  38121. case 140:
  38122. yyaccept = 0;
  38123. yych = this._charAt(YYMARKER = ++cursor);
  38124. if (yych == '\n') { gotoCase = 137; continue; };
  38125. if (yych == '\r') { gotoCase = 137; continue; };
  38126. { gotoCase = 252; continue; };
  38127. case 141:
  38128. yyaccept = 1;
  38129. yych = this._charAt(YYMARKER = ++cursor);
  38130. { gotoCase = 170; continue; };
  38131. case 142:
  38132. this.setLexCondition(this._lexConditions.DIV);
  38133. {
  38134. var token = this._line.substring(cursorOnEnter, cursor);
  38135. if (WebInspector.SourceJavaScriptTokenizer.Keywords[token] === true && token !== "__proto__")
  38136. this.tokenType = "javascript-keyword";
  38137. else
  38138. this.tokenType = "javascript-ident";
  38139. return cursor;
  38140. }
  38141. case 143:
  38142. yych = this._charAt(++cursor);
  38143. if (yych == '=') { gotoCase = 163; continue; };
  38144. { gotoCase = 139; continue; };
  38145. case 144:
  38146. yych = this._charAt(++cursor);
  38147. if (yych == '&') { gotoCase = 163; continue; };
  38148. if (yych == '=') { gotoCase = 163; continue; };
  38149. { gotoCase = 139; continue; };
  38150. case 145:
  38151. yyaccept = 0;
  38152. yych = this._charAt(YYMARKER = ++cursor);
  38153. if (yych == '\n') { gotoCase = 137; continue; };
  38154. if (yych == '\r') { gotoCase = 137; continue; };
  38155. { gotoCase = 241; continue; };
  38156. case 146:
  38157. yych = this._charAt(++cursor);
  38158. { gotoCase = 139; continue; };
  38159. case 147:
  38160. ++cursor;
  38161. this.setLexCondition(this._lexConditions.DIV);
  38162. { this.tokenType = null; return cursor; }
  38163. case 149:
  38164. yych = this._charAt(++cursor);
  38165. if (yych == '=') { gotoCase = 163; continue; };
  38166. { gotoCase = 139; continue; };
  38167. case 150:
  38168. yych = this._charAt(++cursor);
  38169. if (yych == '+') { gotoCase = 163; continue; };
  38170. if (yych == '=') { gotoCase = 163; continue; };
  38171. { gotoCase = 139; continue; };
  38172. case 151:
  38173. yych = this._charAt(++cursor);
  38174. if (yych == '-') { gotoCase = 163; continue; };
  38175. if (yych == '=') { gotoCase = 163; continue; };
  38176. { gotoCase = 139; continue; };
  38177. case 152:
  38178. yych = this._charAt(++cursor);
  38179. if (yych <= '/') { gotoCase = 139; continue; };
  38180. if (yych <= '9') { gotoCase = 234; continue; };
  38181. { gotoCase = 139; continue; };
  38182. case 153:
  38183. yyaccept = 0;
  38184. yych = this._charAt(YYMARKER = ++cursor);
  38185. if (yych <= '*') {
  38186. if (yych <= '\f') {
  38187. if (yych == '\n') { gotoCase = 137; continue; };
  38188. { gotoCase = 197; continue; };
  38189. } else {
  38190. if (yych <= '\r') { gotoCase = 137; continue; };
  38191. if (yych <= ')') { gotoCase = 197; continue; };
  38192. { gotoCase = 202; continue; };
  38193. }
  38194. } else {
  38195. if (yych <= 'Z') {
  38196. if (yych == '/') { gotoCase = 204; continue; };
  38197. { gotoCase = 197; continue; };
  38198. } else {
  38199. if (yych <= '[') { gotoCase = 200; continue; };
  38200. if (yych <= '\\') { gotoCase = 199; continue; };
  38201. if (yych <= ']') { gotoCase = 137; continue; };
  38202. { gotoCase = 197; continue; };
  38203. }
  38204. }
  38205. case 154:
  38206. yyaccept = 2;
  38207. yych = this._charAt(YYMARKER = ++cursor);
  38208. if (yych <= 'E') {
  38209. if (yych <= '/') {
  38210. if (yych == '.') { gotoCase = 183; continue; };
  38211. } else {
  38212. if (yych <= '7') { gotoCase = 192; continue; };
  38213. if (yych >= 'E') { gotoCase = 182; continue; };
  38214. }
  38215. } else {
  38216. if (yych <= 'd') {
  38217. if (yych == 'X') { gotoCase = 194; continue; };
  38218. } else {
  38219. if (yych <= 'e') { gotoCase = 182; continue; };
  38220. if (yych == 'x') { gotoCase = 194; continue; };
  38221. }
  38222. }
  38223. case 155:
  38224. this.setLexCondition(this._lexConditions.DIV);
  38225. { this.tokenType = "javascript-number"; return cursor; }
  38226. case 156:
  38227. yyaccept = 2;
  38228. yych = this._charAt(YYMARKER = ++cursor);
  38229. if (yych <= '9') {
  38230. if (yych == '.') { gotoCase = 183; continue; };
  38231. if (yych <= '/') { gotoCase = 155; continue; };
  38232. { gotoCase = 180; continue; };
  38233. } else {
  38234. if (yych <= 'E') {
  38235. if (yych <= 'D') { gotoCase = 155; continue; };
  38236. { gotoCase = 182; continue; };
  38237. } else {
  38238. if (yych == 'e') { gotoCase = 182; continue; };
  38239. { gotoCase = 155; continue; };
  38240. }
  38241. }
  38242. case 157:
  38243. yych = this._charAt(++cursor);
  38244. if (yych <= ';') { gotoCase = 139; continue; };
  38245. if (yych <= '<') { gotoCase = 179; continue; };
  38246. if (yych <= '=') { gotoCase = 163; continue; };
  38247. { gotoCase = 139; continue; };
  38248. case 158:
  38249. yych = this._charAt(++cursor);
  38250. if (yych == '=') { gotoCase = 178; continue; };
  38251. { gotoCase = 139; continue; };
  38252. case 159:
  38253. yych = this._charAt(++cursor);
  38254. if (yych <= '<') { gotoCase = 139; continue; };
  38255. if (yych <= '=') { gotoCase = 163; continue; };
  38256. if (yych <= '>') { gotoCase = 176; continue; };
  38257. { gotoCase = 139; continue; };
  38258. case 160:
  38259. yyaccept = 0;
  38260. yych = this._charAt(YYMARKER = ++cursor);
  38261. if (yych == 'u') { gotoCase = 164; continue; };
  38262. { gotoCase = 137; continue; };
  38263. case 161:
  38264. yych = this._charAt(++cursor);
  38265. if (yych == '=') { gotoCase = 163; continue; };
  38266. { gotoCase = 139; continue; };
  38267. case 162:
  38268. yych = this._charAt(++cursor);
  38269. if (yych == '=') { gotoCase = 163; continue; };
  38270. if (yych != '|') { gotoCase = 139; continue; };
  38271. case 163:
  38272. yych = this._charAt(++cursor);
  38273. { gotoCase = 139; continue; };
  38274. case 164:
  38275. yych = this._charAt(++cursor);
  38276. if (yych <= '@') {
  38277. if (yych <= '/') { gotoCase = 165; continue; };
  38278. if (yych <= '9') { gotoCase = 166; continue; };
  38279. } else {
  38280. if (yych <= 'F') { gotoCase = 166; continue; };
  38281. if (yych <= '`') { gotoCase = 165; continue; };
  38282. if (yych <= 'f') { gotoCase = 166; continue; };
  38283. }
  38284. case 165:
  38285. cursor = YYMARKER;
  38286. if (yyaccept <= 1) {
  38287. if (yyaccept <= 0) {
  38288. { gotoCase = 137; continue; };
  38289. } else {
  38290. { gotoCase = 142; continue; };
  38291. }
  38292. } else {
  38293. if (yyaccept <= 2) {
  38294. { gotoCase = 155; continue; };
  38295. } else {
  38296. { gotoCase = 217; continue; };
  38297. }
  38298. }
  38299. case 166:
  38300. yych = this._charAt(++cursor);
  38301. if (yych <= '@') {
  38302. if (yych <= '/') { gotoCase = 165; continue; };
  38303. if (yych >= ':') { gotoCase = 165; continue; };
  38304. } else {
  38305. if (yych <= 'F') { gotoCase = 167; continue; };
  38306. if (yych <= '`') { gotoCase = 165; continue; };
  38307. if (yych >= 'g') { gotoCase = 165; continue; };
  38308. }
  38309. case 167:
  38310. yych = this._charAt(++cursor);
  38311. if (yych <= '@') {
  38312. if (yych <= '/') { gotoCase = 165; continue; };
  38313. if (yych >= ':') { gotoCase = 165; continue; };
  38314. } else {
  38315. if (yych <= 'F') { gotoCase = 168; continue; };
  38316. if (yych <= '`') { gotoCase = 165; continue; };
  38317. if (yych >= 'g') { gotoCase = 165; continue; };
  38318. }
  38319. case 168:
  38320. yych = this._charAt(++cursor);
  38321. if (yych <= '@') {
  38322. if (yych <= '/') { gotoCase = 165; continue; };
  38323. if (yych >= ':') { gotoCase = 165; continue; };
  38324. } else {
  38325. if (yych <= 'F') { gotoCase = 169; continue; };
  38326. if (yych <= '`') { gotoCase = 165; continue; };
  38327. if (yych >= 'g') { gotoCase = 165; continue; };
  38328. }
  38329. case 169:
  38330. yyaccept = 1;
  38331. YYMARKER = ++cursor;
  38332. yych = this._charAt(cursor);
  38333. case 170:
  38334. if (yych <= '[') {
  38335. if (yych <= '/') {
  38336. if (yych == '$') { gotoCase = 169; continue; };
  38337. { gotoCase = 142; continue; };
  38338. } else {
  38339. if (yych <= '9') { gotoCase = 169; continue; };
  38340. if (yych <= '@') { gotoCase = 142; continue; };
  38341. if (yych <= 'Z') { gotoCase = 169; continue; };
  38342. { gotoCase = 142; continue; };
  38343. }
  38344. } else {
  38345. if (yych <= '_') {
  38346. if (yych <= '\\') { gotoCase = 171; continue; };
  38347. if (yych <= '^') { gotoCase = 142; continue; };
  38348. { gotoCase = 169; continue; };
  38349. } else {
  38350. if (yych <= '`') { gotoCase = 142; continue; };
  38351. if (yych <= 'z') { gotoCase = 169; continue; };
  38352. if (yych <= String.fromCharCode(0x7F)) { gotoCase = 142; continue; };
  38353. { gotoCase = 169; continue; };
  38354. }
  38355. }
  38356. case 171:
  38357. ++cursor;
  38358. yych = this._charAt(cursor);
  38359. if (yych != 'u') { gotoCase = 165; continue; };
  38360. ++cursor;
  38361. yych = this._charAt(cursor);
  38362. if (yych <= '@') {
  38363. if (yych <= '/') { gotoCase = 165; continue; };
  38364. if (yych >= ':') { gotoCase = 165; continue; };
  38365. } else {
  38366. if (yych <= 'F') { gotoCase = 173; continue; };
  38367. if (yych <= '`') { gotoCase = 165; continue; };
  38368. if (yych >= 'g') { gotoCase = 165; continue; };
  38369. }
  38370. case 173:
  38371. ++cursor;
  38372. yych = this._charAt(cursor);
  38373. if (yych <= '@') {
  38374. if (yych <= '/') { gotoCase = 165; continue; };
  38375. if (yych >= ':') { gotoCase = 165; continue; };
  38376. } else {
  38377. if (yych <= 'F') { gotoCase = 174; continue; };
  38378. if (yych <= '`') { gotoCase = 165; continue; };
  38379. if (yych >= 'g') { gotoCase = 165; continue; };
  38380. }
  38381. case 174:
  38382. ++cursor;
  38383. yych = this._charAt(cursor);
  38384. if (yych <= '@') {
  38385. if (yych <= '/') { gotoCase = 165; continue; };
  38386. if (yych >= ':') { gotoCase = 165; continue; };
  38387. } else {
  38388. if (yych <= 'F') { gotoCase = 175; continue; };
  38389. if (yych <= '`') { gotoCase = 165; continue; };
  38390. if (yych >= 'g') { gotoCase = 165; continue; };
  38391. }
  38392. case 175:
  38393. ++cursor;
  38394. yych = this._charAt(cursor);
  38395. if (yych <= '@') {
  38396. if (yych <= '/') { gotoCase = 165; continue; };
  38397. if (yych <= '9') { gotoCase = 169; continue; };
  38398. { gotoCase = 165; continue; };
  38399. } else {
  38400. if (yych <= 'F') { gotoCase = 169; continue; };
  38401. if (yych <= '`') { gotoCase = 165; continue; };
  38402. if (yych <= 'f') { gotoCase = 169; continue; };
  38403. { gotoCase = 165; continue; };
  38404. }
  38405. case 176:
  38406. yych = this._charAt(++cursor);
  38407. if (yych <= '<') { gotoCase = 139; continue; };
  38408. if (yych <= '=') { gotoCase = 163; continue; };
  38409. if (yych >= '?') { gotoCase = 139; continue; };
  38410. yych = this._charAt(++cursor);
  38411. if (yych == '=') { gotoCase = 163; continue; };
  38412. { gotoCase = 139; continue; };
  38413. case 178:
  38414. yych = this._charAt(++cursor);
  38415. if (yych == '=') { gotoCase = 163; continue; };
  38416. { gotoCase = 139; continue; };
  38417. case 179:
  38418. yych = this._charAt(++cursor);
  38419. if (yych == '=') { gotoCase = 163; continue; };
  38420. { gotoCase = 139; continue; };
  38421. case 180:
  38422. yyaccept = 2;
  38423. YYMARKER = ++cursor;
  38424. yych = this._charAt(cursor);
  38425. if (yych <= '9') {
  38426. if (yych == '.') { gotoCase = 183; continue; };
  38427. if (yych <= '/') { gotoCase = 155; continue; };
  38428. { gotoCase = 180; continue; };
  38429. } else {
  38430. if (yych <= 'E') {
  38431. if (yych <= 'D') { gotoCase = 155; continue; };
  38432. } else {
  38433. if (yych != 'e') { gotoCase = 155; continue; };
  38434. }
  38435. }
  38436. case 182:
  38437. yych = this._charAt(++cursor);
  38438. if (yych <= ',') {
  38439. if (yych == '+') { gotoCase = 189; continue; };
  38440. { gotoCase = 165; continue; };
  38441. } else {
  38442. if (yych <= '-') { gotoCase = 189; continue; };
  38443. if (yych <= '/') { gotoCase = 165; continue; };
  38444. if (yych <= '9') { gotoCase = 190; continue; };
  38445. { gotoCase = 165; continue; };
  38446. }
  38447. case 183:
  38448. yyaccept = 2;
  38449. YYMARKER = ++cursor;
  38450. yych = this._charAt(cursor);
  38451. if (yych <= 'D') {
  38452. if (yych <= '/') { gotoCase = 155; continue; };
  38453. if (yych <= '9') { gotoCase = 183; continue; };
  38454. { gotoCase = 155; continue; };
  38455. } else {
  38456. if (yych <= 'E') { gotoCase = 185; continue; };
  38457. if (yych != 'e') { gotoCase = 155; continue; };
  38458. }
  38459. case 185:
  38460. yych = this._charAt(++cursor);
  38461. if (yych <= ',') {
  38462. if (yych != '+') { gotoCase = 165; continue; };
  38463. } else {
  38464. if (yych <= '-') { gotoCase = 186; continue; };
  38465. if (yych <= '/') { gotoCase = 165; continue; };
  38466. if (yych <= '9') { gotoCase = 187; continue; };
  38467. { gotoCase = 165; continue; };
  38468. }
  38469. case 186:
  38470. yych = this._charAt(++cursor);
  38471. if (yych <= '/') { gotoCase = 165; continue; };
  38472. if (yych >= ':') { gotoCase = 165; continue; };
  38473. case 187:
  38474. ++cursor;
  38475. yych = this._charAt(cursor);
  38476. if (yych <= '/') { gotoCase = 155; continue; };
  38477. if (yych <= '9') { gotoCase = 187; continue; };
  38478. { gotoCase = 155; continue; };
  38479. case 189:
  38480. yych = this._charAt(++cursor);
  38481. if (yych <= '/') { gotoCase = 165; continue; };
  38482. if (yych >= ':') { gotoCase = 165; continue; };
  38483. case 190:
  38484. ++cursor;
  38485. yych = this._charAt(cursor);
  38486. if (yych <= '/') { gotoCase = 155; continue; };
  38487. if (yych <= '9') { gotoCase = 190; continue; };
  38488. { gotoCase = 155; continue; };
  38489. case 192:
  38490. ++cursor;
  38491. yych = this._charAt(cursor);
  38492. if (yych <= '/') { gotoCase = 155; continue; };
  38493. if (yych <= '7') { gotoCase = 192; continue; };
  38494. { gotoCase = 155; continue; };
  38495. case 194:
  38496. yych = this._charAt(++cursor);
  38497. if (yych <= '@') {
  38498. if (yych <= '/') { gotoCase = 165; continue; };
  38499. if (yych >= ':') { gotoCase = 165; continue; };
  38500. } else {
  38501. if (yych <= 'F') { gotoCase = 195; continue; };
  38502. if (yych <= '`') { gotoCase = 165; continue; };
  38503. if (yych >= 'g') { gotoCase = 165; continue; };
  38504. }
  38505. case 195:
  38506. ++cursor;
  38507. yych = this._charAt(cursor);
  38508. if (yych <= '@') {
  38509. if (yych <= '/') { gotoCase = 155; continue; };
  38510. if (yych <= '9') { gotoCase = 195; continue; };
  38511. { gotoCase = 155; continue; };
  38512. } else {
  38513. if (yych <= 'F') { gotoCase = 195; continue; };
  38514. if (yych <= '`') { gotoCase = 155; continue; };
  38515. if (yych <= 'f') { gotoCase = 195; continue; };
  38516. { gotoCase = 155; continue; };
  38517. }
  38518. case 197:
  38519. ++cursor;
  38520. yych = this._charAt(cursor);
  38521. if (yych <= '.') {
  38522. if (yych <= '\n') {
  38523. if (yych <= '\t') { gotoCase = 197; continue; };
  38524. { gotoCase = 165; continue; };
  38525. } else {
  38526. if (yych == '\r') { gotoCase = 165; continue; };
  38527. { gotoCase = 197; continue; };
  38528. }
  38529. } else {
  38530. if (yych <= '[') {
  38531. if (yych <= '/') { gotoCase = 220; continue; };
  38532. if (yych <= 'Z') { gotoCase = 197; continue; };
  38533. { gotoCase = 228; continue; };
  38534. } else {
  38535. if (yych <= '\\') { gotoCase = 227; continue; };
  38536. if (yych <= ']') { gotoCase = 165; continue; };
  38537. { gotoCase = 197; continue; };
  38538. }
  38539. }
  38540. case 199:
  38541. yych = this._charAt(++cursor);
  38542. if (yych == '\n') { gotoCase = 165; continue; };
  38543. if (yych == '\r') { gotoCase = 165; continue; };
  38544. { gotoCase = 197; continue; };
  38545. case 200:
  38546. ++cursor;
  38547. yych = this._charAt(cursor);
  38548. if (yych <= '*') {
  38549. if (yych <= '\f') {
  38550. if (yych == '\n') { gotoCase = 165; continue; };
  38551. { gotoCase = 200; continue; };
  38552. } else {
  38553. if (yych <= '\r') { gotoCase = 165; continue; };
  38554. if (yych <= ')') { gotoCase = 200; continue; };
  38555. { gotoCase = 165; continue; };
  38556. }
  38557. } else {
  38558. if (yych <= '[') {
  38559. if (yych == '/') { gotoCase = 165; continue; };
  38560. { gotoCase = 200; continue; };
  38561. } else {
  38562. if (yych <= '\\') { gotoCase = 215; continue; };
  38563. if (yych <= ']') { gotoCase = 213; continue; };
  38564. { gotoCase = 200; continue; };
  38565. }
  38566. }
  38567. case 202:
  38568. ++cursor;
  38569. yych = this._charAt(cursor);
  38570. if (yych <= '\f') {
  38571. if (yych == '\n') { gotoCase = 209; continue; };
  38572. { gotoCase = 202; continue; };
  38573. } else {
  38574. if (yych <= '\r') { gotoCase = 209; continue; };
  38575. if (yych == '*') { gotoCase = 207; continue; };
  38576. { gotoCase = 202; continue; };
  38577. }
  38578. case 204:
  38579. ++cursor;
  38580. yych = this._charAt(cursor);
  38581. if (yych == '\n') { gotoCase = 206; continue; };
  38582. if (yych != '\r') { gotoCase = 204; continue; };
  38583. case 206:
  38584. { this.tokenType = "javascript-comment"; return cursor; }
  38585. case 207:
  38586. ++cursor;
  38587. yych = this._charAt(cursor);
  38588. if (yych == '*') { gotoCase = 207; continue; };
  38589. if (yych == '/') { gotoCase = 211; continue; };
  38590. { gotoCase = 202; continue; };
  38591. case 209:
  38592. ++cursor;
  38593. this.setLexCondition(this._lexConditions.COMMENT);
  38594. { this.tokenType = "javascript-comment"; return cursor; }
  38595. case 211:
  38596. ++cursor;
  38597. { this.tokenType = "javascript-comment"; return cursor; }
  38598. case 213:
  38599. ++cursor;
  38600. yych = this._charAt(cursor);
  38601. if (yych <= '*') {
  38602. if (yych <= '\f') {
  38603. if (yych == '\n') { gotoCase = 165; continue; };
  38604. { gotoCase = 213; continue; };
  38605. } else {
  38606. if (yych <= '\r') { gotoCase = 165; continue; };
  38607. if (yych <= ')') { gotoCase = 213; continue; };
  38608. { gotoCase = 197; continue; };
  38609. }
  38610. } else {
  38611. if (yych <= 'Z') {
  38612. if (yych == '/') { gotoCase = 220; continue; };
  38613. { gotoCase = 213; continue; };
  38614. } else {
  38615. if (yych <= '[') { gotoCase = 218; continue; };
  38616. if (yych <= '\\') { gotoCase = 216; continue; };
  38617. { gotoCase = 213; continue; };
  38618. }
  38619. }
  38620. case 215:
  38621. ++cursor;
  38622. yych = this._charAt(cursor);
  38623. if (yych == '\n') { gotoCase = 165; continue; };
  38624. if (yych == '\r') { gotoCase = 165; continue; };
  38625. { gotoCase = 200; continue; };
  38626. case 216:
  38627. yyaccept = 3;
  38628. YYMARKER = ++cursor;
  38629. yych = this._charAt(cursor);
  38630. if (yych == '\n') { gotoCase = 217; continue; };
  38631. if (yych != '\r') { gotoCase = 213; continue; };
  38632. case 217:
  38633. this.setLexCondition(this._lexConditions.REGEX);
  38634. { this.tokenType = "javascript-regexp"; return cursor; }
  38635. case 218:
  38636. ++cursor;
  38637. yych = this._charAt(cursor);
  38638. if (yych <= '*') {
  38639. if (yych <= '\f') {
  38640. if (yych == '\n') { gotoCase = 165; continue; };
  38641. { gotoCase = 218; continue; };
  38642. } else {
  38643. if (yych <= '\r') { gotoCase = 165; continue; };
  38644. if (yych <= ')') { gotoCase = 218; continue; };
  38645. { gotoCase = 165; continue; };
  38646. }
  38647. } else {
  38648. if (yych <= '[') {
  38649. if (yych == '/') { gotoCase = 165; continue; };
  38650. { gotoCase = 218; continue; };
  38651. } else {
  38652. if (yych <= '\\') { gotoCase = 225; continue; };
  38653. if (yych <= ']') { gotoCase = 223; continue; };
  38654. { gotoCase = 218; continue; };
  38655. }
  38656. }
  38657. case 220:
  38658. ++cursor;
  38659. yych = this._charAt(cursor);
  38660. if (yych <= 'h') {
  38661. if (yych == 'g') { gotoCase = 220; continue; };
  38662. } else {
  38663. if (yych <= 'i') { gotoCase = 220; continue; };
  38664. if (yych == 'm') { gotoCase = 220; continue; };
  38665. }
  38666. { this.tokenType = "javascript-regexp"; return cursor; }
  38667. case 223:
  38668. ++cursor;
  38669. yych = this._charAt(cursor);
  38670. if (yych <= '*') {
  38671. if (yych <= '\f') {
  38672. if (yych == '\n') { gotoCase = 165; continue; };
  38673. { gotoCase = 223; continue; };
  38674. } else {
  38675. if (yych <= '\r') { gotoCase = 165; continue; };
  38676. if (yych <= ')') { gotoCase = 223; continue; };
  38677. { gotoCase = 197; continue; };
  38678. }
  38679. } else {
  38680. if (yych <= 'Z') {
  38681. if (yych == '/') { gotoCase = 220; continue; };
  38682. { gotoCase = 223; continue; };
  38683. } else {
  38684. if (yych <= '[') { gotoCase = 218; continue; };
  38685. if (yych <= '\\') { gotoCase = 226; continue; };
  38686. { gotoCase = 223; continue; };
  38687. }
  38688. }
  38689. case 225:
  38690. ++cursor;
  38691. yych = this._charAt(cursor);
  38692. if (yych == '\n') { gotoCase = 165; continue; };
  38693. if (yych == '\r') { gotoCase = 165; continue; };
  38694. { gotoCase = 218; continue; };
  38695. case 226:
  38696. yyaccept = 3;
  38697. YYMARKER = ++cursor;
  38698. yych = this._charAt(cursor);
  38699. if (yych == '\n') { gotoCase = 217; continue; };
  38700. if (yych == '\r') { gotoCase = 217; continue; };
  38701. { gotoCase = 223; continue; };
  38702. case 227:
  38703. yyaccept = 3;
  38704. YYMARKER = ++cursor;
  38705. yych = this._charAt(cursor);
  38706. if (yych == '\n') { gotoCase = 217; continue; };
  38707. if (yych == '\r') { gotoCase = 217; continue; };
  38708. { gotoCase = 197; continue; };
  38709. case 228:
  38710. ++cursor;
  38711. yych = this._charAt(cursor);
  38712. if (yych <= '*') {
  38713. if (yych <= '\f') {
  38714. if (yych == '\n') { gotoCase = 165; continue; };
  38715. { gotoCase = 228; continue; };
  38716. } else {
  38717. if (yych <= '\r') { gotoCase = 165; continue; };
  38718. if (yych <= ')') { gotoCase = 228; continue; };
  38719. { gotoCase = 165; continue; };
  38720. }
  38721. } else {
  38722. if (yych <= '[') {
  38723. if (yych == '/') { gotoCase = 165; continue; };
  38724. { gotoCase = 228; continue; };
  38725. } else {
  38726. if (yych <= '\\') { gotoCase = 232; continue; };
  38727. if (yych >= '^') { gotoCase = 228; continue; };
  38728. }
  38729. }
  38730. case 230:
  38731. ++cursor;
  38732. yych = this._charAt(cursor);
  38733. if (yych <= '*') {
  38734. if (yych <= '\f') {
  38735. if (yych == '\n') { gotoCase = 165; continue; };
  38736. { gotoCase = 230; continue; };
  38737. } else {
  38738. if (yych <= '\r') { gotoCase = 165; continue; };
  38739. if (yych <= ')') { gotoCase = 230; continue; };
  38740. { gotoCase = 197; continue; };
  38741. }
  38742. } else {
  38743. if (yych <= 'Z') {
  38744. if (yych == '/') { gotoCase = 220; continue; };
  38745. { gotoCase = 230; continue; };
  38746. } else {
  38747. if (yych <= '[') { gotoCase = 228; continue; };
  38748. if (yych <= '\\') { gotoCase = 233; continue; };
  38749. { gotoCase = 230; continue; };
  38750. }
  38751. }
  38752. case 232:
  38753. ++cursor;
  38754. yych = this._charAt(cursor);
  38755. if (yych == '\n') { gotoCase = 165; continue; };
  38756. if (yych == '\r') { gotoCase = 165; continue; };
  38757. { gotoCase = 228; continue; };
  38758. case 233:
  38759. yyaccept = 3;
  38760. YYMARKER = ++cursor;
  38761. yych = this._charAt(cursor);
  38762. if (yych == '\n') { gotoCase = 217; continue; };
  38763. if (yych == '\r') { gotoCase = 217; continue; };
  38764. { gotoCase = 230; continue; };
  38765. case 234:
  38766. yyaccept = 2;
  38767. YYMARKER = ++cursor;
  38768. yych = this._charAt(cursor);
  38769. if (yych <= 'D') {
  38770. if (yych <= '/') { gotoCase = 155; continue; };
  38771. if (yych <= '9') { gotoCase = 234; continue; };
  38772. { gotoCase = 155; continue; };
  38773. } else {
  38774. if (yych <= 'E') { gotoCase = 236; continue; };
  38775. if (yych != 'e') { gotoCase = 155; continue; };
  38776. }
  38777. case 236:
  38778. yych = this._charAt(++cursor);
  38779. if (yych <= ',') {
  38780. if (yych != '+') { gotoCase = 165; continue; };
  38781. } else {
  38782. if (yych <= '-') { gotoCase = 237; continue; };
  38783. if (yych <= '/') { gotoCase = 165; continue; };
  38784. if (yych <= '9') { gotoCase = 238; continue; };
  38785. { gotoCase = 165; continue; };
  38786. }
  38787. case 237:
  38788. yych = this._charAt(++cursor);
  38789. if (yych <= '/') { gotoCase = 165; continue; };
  38790. if (yych >= ':') { gotoCase = 165; continue; };
  38791. case 238:
  38792. ++cursor;
  38793. yych = this._charAt(cursor);
  38794. if (yych <= '/') { gotoCase = 155; continue; };
  38795. if (yych <= '9') { gotoCase = 238; continue; };
  38796. { gotoCase = 155; continue; };
  38797. case 240:
  38798. ++cursor;
  38799. yych = this._charAt(cursor);
  38800. case 241:
  38801. if (yych <= '\r') {
  38802. if (yych == '\n') { gotoCase = 165; continue; };
  38803. if (yych <= '\f') { gotoCase = 240; continue; };
  38804. { gotoCase = 165; continue; };
  38805. } else {
  38806. if (yych <= '\'') {
  38807. if (yych <= '&') { gotoCase = 240; continue; };
  38808. { gotoCase = 243; continue; };
  38809. } else {
  38810. if (yych != '\\') { gotoCase = 240; continue; };
  38811. }
  38812. }
  38813. ++cursor;
  38814. yych = this._charAt(cursor);
  38815. if (yych <= 'a') {
  38816. if (yych <= '!') {
  38817. if (yych <= '\n') {
  38818. if (yych <= '\t') { gotoCase = 165; continue; };
  38819. { gotoCase = 246; continue; };
  38820. } else {
  38821. if (yych == '\r') { gotoCase = 246; continue; };
  38822. { gotoCase = 165; continue; };
  38823. }
  38824. } else {
  38825. if (yych <= '\'') {
  38826. if (yych <= '"') { gotoCase = 240; continue; };
  38827. if (yych <= '&') { gotoCase = 165; continue; };
  38828. { gotoCase = 240; continue; };
  38829. } else {
  38830. if (yych == '\\') { gotoCase = 240; continue; };
  38831. { gotoCase = 165; continue; };
  38832. }
  38833. }
  38834. } else {
  38835. if (yych <= 'q') {
  38836. if (yych <= 'f') {
  38837. if (yych <= 'b') { gotoCase = 240; continue; };
  38838. if (yych <= 'e') { gotoCase = 165; continue; };
  38839. { gotoCase = 240; continue; };
  38840. } else {
  38841. if (yych == 'n') { gotoCase = 240; continue; };
  38842. { gotoCase = 165; continue; };
  38843. }
  38844. } else {
  38845. if (yych <= 't') {
  38846. if (yych == 's') { gotoCase = 165; continue; };
  38847. { gotoCase = 240; continue; };
  38848. } else {
  38849. if (yych <= 'u') { gotoCase = 245; continue; };
  38850. if (yych <= 'v') { gotoCase = 240; continue; };
  38851. { gotoCase = 165; continue; };
  38852. }
  38853. }
  38854. }
  38855. case 243:
  38856. ++cursor;
  38857. { this.tokenType = "javascript-string"; return cursor; }
  38858. case 245:
  38859. ++cursor;
  38860. yych = this._charAt(cursor);
  38861. if (yych <= '@') {
  38862. if (yych <= '/') { gotoCase = 165; continue; };
  38863. if (yych <= '9') { gotoCase = 248; continue; };
  38864. { gotoCase = 165; continue; };
  38865. } else {
  38866. if (yych <= 'F') { gotoCase = 248; continue; };
  38867. if (yych <= '`') { gotoCase = 165; continue; };
  38868. if (yych <= 'f') { gotoCase = 248; continue; };
  38869. { gotoCase = 165; continue; };
  38870. }
  38871. case 246:
  38872. ++cursor;
  38873. this.setLexCondition(this._lexConditions.SSTRING);
  38874. { this.tokenType = "javascript-string"; return cursor; }
  38875. case 248:
  38876. ++cursor;
  38877. yych = this._charAt(cursor);
  38878. if (yych <= '@') {
  38879. if (yych <= '/') { gotoCase = 165; continue; };
  38880. if (yych >= ':') { gotoCase = 165; continue; };
  38881. } else {
  38882. if (yych <= 'F') { gotoCase = 249; continue; };
  38883. if (yych <= '`') { gotoCase = 165; continue; };
  38884. if (yych >= 'g') { gotoCase = 165; continue; };
  38885. }
  38886. case 249:
  38887. ++cursor;
  38888. yych = this._charAt(cursor);
  38889. if (yych <= '@') {
  38890. if (yych <= '/') { gotoCase = 165; continue; };
  38891. if (yych >= ':') { gotoCase = 165; continue; };
  38892. } else {
  38893. if (yych <= 'F') { gotoCase = 250; continue; };
  38894. if (yych <= '`') { gotoCase = 165; continue; };
  38895. if (yych >= 'g') { gotoCase = 165; continue; };
  38896. }
  38897. case 250:
  38898. ++cursor;
  38899. yych = this._charAt(cursor);
  38900. if (yych <= '@') {
  38901. if (yych <= '/') { gotoCase = 165; continue; };
  38902. if (yych <= '9') { gotoCase = 240; continue; };
  38903. { gotoCase = 165; continue; };
  38904. } else {
  38905. if (yych <= 'F') { gotoCase = 240; continue; };
  38906. if (yych <= '`') { gotoCase = 165; continue; };
  38907. if (yych <= 'f') { gotoCase = 240; continue; };
  38908. { gotoCase = 165; continue; };
  38909. }
  38910. case 251:
  38911. ++cursor;
  38912. yych = this._charAt(cursor);
  38913. case 252:
  38914. if (yych <= '\r') {
  38915. if (yych == '\n') { gotoCase = 165; continue; };
  38916. if (yych <= '\f') { gotoCase = 251; continue; };
  38917. { gotoCase = 165; continue; };
  38918. } else {
  38919. if (yych <= '"') {
  38920. if (yych <= '!') { gotoCase = 251; continue; };
  38921. { gotoCase = 243; continue; };
  38922. } else {
  38923. if (yych != '\\') { gotoCase = 251; continue; };
  38924. }
  38925. }
  38926. ++cursor;
  38927. yych = this._charAt(cursor);
  38928. if (yych <= 'a') {
  38929. if (yych <= '!') {
  38930. if (yych <= '\n') {
  38931. if (yych <= '\t') { gotoCase = 165; continue; };
  38932. { gotoCase = 255; continue; };
  38933. } else {
  38934. if (yych == '\r') { gotoCase = 255; continue; };
  38935. { gotoCase = 165; continue; };
  38936. }
  38937. } else {
  38938. if (yych <= '\'') {
  38939. if (yych <= '"') { gotoCase = 251; continue; };
  38940. if (yych <= '&') { gotoCase = 165; continue; };
  38941. { gotoCase = 251; continue; };
  38942. } else {
  38943. if (yych == '\\') { gotoCase = 251; continue; };
  38944. { gotoCase = 165; continue; };
  38945. }
  38946. }
  38947. } else {
  38948. if (yych <= 'q') {
  38949. if (yych <= 'f') {
  38950. if (yych <= 'b') { gotoCase = 251; continue; };
  38951. if (yych <= 'e') { gotoCase = 165; continue; };
  38952. { gotoCase = 251; continue; };
  38953. } else {
  38954. if (yych == 'n') { gotoCase = 251; continue; };
  38955. { gotoCase = 165; continue; };
  38956. }
  38957. } else {
  38958. if (yych <= 't') {
  38959. if (yych == 's') { gotoCase = 165; continue; };
  38960. { gotoCase = 251; continue; };
  38961. } else {
  38962. if (yych <= 'u') { gotoCase = 254; continue; };
  38963. if (yych <= 'v') { gotoCase = 251; continue; };
  38964. { gotoCase = 165; continue; };
  38965. }
  38966. }
  38967. }
  38968. case 254:
  38969. ++cursor;
  38970. yych = this._charAt(cursor);
  38971. if (yych <= '@') {
  38972. if (yych <= '/') { gotoCase = 165; continue; };
  38973. if (yych <= '9') { gotoCase = 257; continue; };
  38974. { gotoCase = 165; continue; };
  38975. } else {
  38976. if (yych <= 'F') { gotoCase = 257; continue; };
  38977. if (yych <= '`') { gotoCase = 165; continue; };
  38978. if (yych <= 'f') { gotoCase = 257; continue; };
  38979. { gotoCase = 165; continue; };
  38980. }
  38981. case 255:
  38982. ++cursor;
  38983. this.setLexCondition(this._lexConditions.DSTRING);
  38984. { this.tokenType = "javascript-string"; return cursor; }
  38985. case 257:
  38986. ++cursor;
  38987. yych = this._charAt(cursor);
  38988. if (yych <= '@') {
  38989. if (yych <= '/') { gotoCase = 165; continue; };
  38990. if (yych >= ':') { gotoCase = 165; continue; };
  38991. } else {
  38992. if (yych <= 'F') { gotoCase = 258; continue; };
  38993. if (yych <= '`') { gotoCase = 165; continue; };
  38994. if (yych >= 'g') { gotoCase = 165; continue; };
  38995. }
  38996. case 258:
  38997. ++cursor;
  38998. yych = this._charAt(cursor);
  38999. if (yych <= '@') {
  39000. if (yych <= '/') { gotoCase = 165; continue; };
  39001. if (yych >= ':') { gotoCase = 165; continue; };
  39002. } else {
  39003. if (yych <= 'F') { gotoCase = 259; continue; };
  39004. if (yych <= '`') { gotoCase = 165; continue; };
  39005. if (yych >= 'g') { gotoCase = 165; continue; };
  39006. }
  39007. case 259:
  39008. ++cursor;
  39009. yych = this._charAt(cursor);
  39010. if (yych <= '@') {
  39011. if (yych <= '/') { gotoCase = 165; continue; };
  39012. if (yych <= '9') { gotoCase = 251; continue; };
  39013. { gotoCase = 165; continue; };
  39014. } else {
  39015. if (yych <= 'F') { gotoCase = 251; continue; };
  39016. if (yych <= '`') { gotoCase = 165; continue; };
  39017. if (yych <= 'f') { gotoCase = 251; continue; };
  39018. { gotoCase = 165; continue; };
  39019. }
  39020. case 260:
  39021. ++cursor;
  39022. if ((yych = this._charAt(cursor)) == '=') { gotoCase = 163; continue; };
  39023. { gotoCase = 139; continue; };
  39024.  
  39025. case this.case_REGEX:
  39026. yych = this._charAt(cursor);
  39027. if (yych <= '.') {
  39028. if (yych <= '\n') {
  39029. if (yych <= '\t') { gotoCase = 264; continue; };
  39030. { gotoCase = 265; continue; };
  39031. } else {
  39032. if (yych == '\r') { gotoCase = 265; continue; };
  39033. { gotoCase = 264; continue; };
  39034. }
  39035. } else {
  39036. if (yych <= '[') {
  39037. if (yych <= '/') { gotoCase = 267; continue; };
  39038. if (yych <= 'Z') { gotoCase = 264; continue; };
  39039. { gotoCase = 269; continue; };
  39040. } else {
  39041. if (yych <= '\\') { gotoCase = 270; continue; };
  39042. if (yych <= ']') { gotoCase = 265; continue; };
  39043. { gotoCase = 264; continue; };
  39044. }
  39045. }
  39046. case 263:
  39047. { this.tokenType = "javascript-regexp"; return cursor; }
  39048. case 264:
  39049. yyaccept = 0;
  39050. yych = this._charAt(YYMARKER = ++cursor);
  39051. { gotoCase = 272; continue; };
  39052. case 265:
  39053. ++cursor;
  39054. case 266:
  39055. { this.tokenType = null; return cursor; }
  39056. case 267:
  39057. ++cursor;
  39058. yych = this._charAt(cursor);
  39059. { gotoCase = 278; continue; };
  39060. case 268:
  39061. this.setLexCondition(this._lexConditions.NODIV);
  39062. { this.tokenType = "javascript-regexp"; return cursor; }
  39063. case 269:
  39064. yyaccept = 1;
  39065. yych = this._charAt(YYMARKER = ++cursor);
  39066. if (yych <= '\r') {
  39067. if (yych == '\n') { gotoCase = 266; continue; };
  39068. if (yych <= '\f') { gotoCase = 276; continue; };
  39069. { gotoCase = 266; continue; };
  39070. } else {
  39071. if (yych <= '*') {
  39072. if (yych <= ')') { gotoCase = 276; continue; };
  39073. { gotoCase = 266; continue; };
  39074. } else {
  39075. if (yych == '/') { gotoCase = 266; continue; };
  39076. { gotoCase = 276; continue; };
  39077. }
  39078. }
  39079. case 270:
  39080. yych = this._charAt(++cursor);
  39081. if (yych == '\n') { gotoCase = 266; continue; };
  39082. if (yych == '\r') { gotoCase = 266; continue; };
  39083. case 271:
  39084. yyaccept = 0;
  39085. YYMARKER = ++cursor;
  39086. yych = this._charAt(cursor);
  39087. case 272:
  39088. if (yych <= '.') {
  39089. if (yych <= '\n') {
  39090. if (yych <= '\t') { gotoCase = 271; continue; };
  39091. { gotoCase = 263; continue; };
  39092. } else {
  39093. if (yych == '\r') { gotoCase = 263; continue; };
  39094. { gotoCase = 271; continue; };
  39095. }
  39096. } else {
  39097. if (yych <= '[') {
  39098. if (yych <= '/') { gotoCase = 277; continue; };
  39099. if (yych <= 'Z') { gotoCase = 271; continue; };
  39100. { gotoCase = 275; continue; };
  39101. } else {
  39102. if (yych <= '\\') { gotoCase = 273; continue; };
  39103. if (yych <= ']') { gotoCase = 263; continue; };
  39104. { gotoCase = 271; continue; };
  39105. }
  39106. }
  39107. case 273:
  39108. ++cursor;
  39109. yych = this._charAt(cursor);
  39110. if (yych == '\n') { gotoCase = 274; continue; };
  39111. if (yych != '\r') { gotoCase = 271; continue; };
  39112. case 274:
  39113. cursor = YYMARKER;
  39114. if (yyaccept <= 0) {
  39115. { gotoCase = 263; continue; };
  39116. } else {
  39117. { gotoCase = 266; continue; };
  39118. }
  39119. case 275:
  39120. ++cursor;
  39121. yych = this._charAt(cursor);
  39122. case 276:
  39123. if (yych <= '*') {
  39124. if (yych <= '\f') {
  39125. if (yych == '\n') { gotoCase = 274; continue; };
  39126. { gotoCase = 275; continue; };
  39127. } else {
  39128. if (yych <= '\r') { gotoCase = 274; continue; };
  39129. if (yych <= ')') { gotoCase = 275; continue; };
  39130. { gotoCase = 274; continue; };
  39131. }
  39132. } else {
  39133. if (yych <= '[') {
  39134. if (yych == '/') { gotoCase = 274; continue; };
  39135. { gotoCase = 275; continue; };
  39136. } else {
  39137. if (yych <= '\\') { gotoCase = 281; continue; };
  39138. if (yych <= ']') { gotoCase = 279; continue; };
  39139. { gotoCase = 275; continue; };
  39140. }
  39141. }
  39142. case 277:
  39143. ++cursor;
  39144. yych = this._charAt(cursor);
  39145. case 278:
  39146. if (yych <= 'h') {
  39147. if (yych == 'g') { gotoCase = 277; continue; };
  39148. { gotoCase = 268; continue; };
  39149. } else {
  39150. if (yych <= 'i') { gotoCase = 277; continue; };
  39151. if (yych == 'm') { gotoCase = 277; continue; };
  39152. { gotoCase = 268; continue; };
  39153. }
  39154. case 279:
  39155. yyaccept = 0;
  39156. YYMARKER = ++cursor;
  39157. yych = this._charAt(cursor);
  39158. if (yych <= '*') {
  39159. if (yych <= '\f') {
  39160. if (yych == '\n') { gotoCase = 263; continue; };
  39161. { gotoCase = 279; continue; };
  39162. } else {
  39163. if (yych <= '\r') { gotoCase = 263; continue; };
  39164. if (yych <= ')') { gotoCase = 279; continue; };
  39165. { gotoCase = 271; continue; };
  39166. }
  39167. } else {
  39168. if (yych <= 'Z') {
  39169. if (yych == '/') { gotoCase = 277; continue; };
  39170. { gotoCase = 279; continue; };
  39171. } else {
  39172. if (yych <= '[') { gotoCase = 275; continue; };
  39173. if (yych <= '\\') { gotoCase = 282; continue; };
  39174. { gotoCase = 279; continue; };
  39175. }
  39176. }
  39177. case 281:
  39178. ++cursor;
  39179. yych = this._charAt(cursor);
  39180. if (yych == '\n') { gotoCase = 274; continue; };
  39181. if (yych == '\r') { gotoCase = 274; continue; };
  39182. { gotoCase = 275; continue; };
  39183. case 282:
  39184. ++cursor;
  39185. yych = this._charAt(cursor);
  39186. if (yych == '\n') { gotoCase = 274; continue; };
  39187. if (yych == '\r') { gotoCase = 274; continue; };
  39188. { gotoCase = 279; continue; };
  39189.  
  39190. case this.case_SSTRING:
  39191. yych = this._charAt(cursor);
  39192. if (yych <= '\r') {
  39193. if (yych == '\n') { gotoCase = 287; continue; };
  39194. if (yych <= '\f') { gotoCase = 286; continue; };
  39195. { gotoCase = 287; continue; };
  39196. } else {
  39197. if (yych <= '\'') {
  39198. if (yych <= '&') { gotoCase = 286; continue; };
  39199. { gotoCase = 289; continue; };
  39200. } else {
  39201. if (yych == '\\') { gotoCase = 291; continue; };
  39202. { gotoCase = 286; continue; };
  39203. }
  39204. }
  39205. case 285:
  39206. { this.tokenType = "javascript-string"; return cursor; }
  39207. case 286:
  39208. yyaccept = 0;
  39209. yych = this._charAt(YYMARKER = ++cursor);
  39210. { gotoCase = 293; continue; };
  39211. case 287:
  39212. ++cursor;
  39213. case 288:
  39214. { this.tokenType = null; return cursor; }
  39215. case 289:
  39216. ++cursor;
  39217. case 290:
  39218. this.setLexCondition(this._lexConditions.NODIV);
  39219. { this.tokenType = "javascript-string"; return cursor; }
  39220. case 291:
  39221. yyaccept = 1;
  39222. yych = this._charAt(YYMARKER = ++cursor);
  39223. if (yych <= 'e') {
  39224. if (yych <= '\'') {
  39225. if (yych == '"') { gotoCase = 292; continue; };
  39226. if (yych <= '&') { gotoCase = 288; continue; };
  39227. } else {
  39228. if (yych <= '\\') {
  39229. if (yych <= '[') { gotoCase = 288; continue; };
  39230. } else {
  39231. if (yych != 'b') { gotoCase = 288; continue; };
  39232. }
  39233. }
  39234. } else {
  39235. if (yych <= 'r') {
  39236. if (yych <= 'm') {
  39237. if (yych >= 'g') { gotoCase = 288; continue; };
  39238. } else {
  39239. if (yych <= 'n') { gotoCase = 292; continue; };
  39240. if (yych <= 'q') { gotoCase = 288; continue; };
  39241. }
  39242. } else {
  39243. if (yych <= 't') {
  39244. if (yych <= 's') { gotoCase = 288; continue; };
  39245. } else {
  39246. if (yych <= 'u') { gotoCase = 294; continue; };
  39247. if (yych >= 'w') { gotoCase = 288; continue; };
  39248. }
  39249. }
  39250. }
  39251. case 292:
  39252. yyaccept = 0;
  39253. YYMARKER = ++cursor;
  39254. yych = this._charAt(cursor);
  39255. case 293:
  39256. if (yych <= '\r') {
  39257. if (yych == '\n') { gotoCase = 285; continue; };
  39258. if (yych <= '\f') { gotoCase = 292; continue; };
  39259. { gotoCase = 285; continue; };
  39260. } else {
  39261. if (yych <= '\'') {
  39262. if (yych <= '&') { gotoCase = 292; continue; };
  39263. { gotoCase = 300; continue; };
  39264. } else {
  39265. if (yych == '\\') { gotoCase = 299; continue; };
  39266. { gotoCase = 292; continue; };
  39267. }
  39268. }
  39269. case 294:
  39270. ++cursor;
  39271. yych = this._charAt(cursor);
  39272. if (yych <= '@') {
  39273. if (yych <= '/') { gotoCase = 295; continue; };
  39274. if (yych <= '9') { gotoCase = 296; continue; };
  39275. } else {
  39276. if (yych <= 'F') { gotoCase = 296; continue; };
  39277. if (yych <= '`') { gotoCase = 295; continue; };
  39278. if (yych <= 'f') { gotoCase = 296; continue; };
  39279. }
  39280. case 295:
  39281. cursor = YYMARKER;
  39282. if (yyaccept <= 0) {
  39283. { gotoCase = 285; continue; };
  39284. } else {
  39285. { gotoCase = 288; continue; };
  39286. }
  39287. case 296:
  39288. ++cursor;
  39289. yych = this._charAt(cursor);
  39290. if (yych <= '@') {
  39291. if (yych <= '/') { gotoCase = 295; continue; };
  39292. if (yych >= ':') { gotoCase = 295; continue; };
  39293. } else {
  39294. if (yych <= 'F') { gotoCase = 297; continue; };
  39295. if (yych <= '`') { gotoCase = 295; continue; };
  39296. if (yych >= 'g') { gotoCase = 295; continue; };
  39297. }
  39298. case 297:
  39299. ++cursor;
  39300. yych = this._charAt(cursor);
  39301. if (yych <= '@') {
  39302. if (yych <= '/') { gotoCase = 295; continue; };
  39303. if (yych >= ':') { gotoCase = 295; continue; };
  39304. } else {
  39305. if (yych <= 'F') { gotoCase = 298; continue; };
  39306. if (yych <= '`') { gotoCase = 295; continue; };
  39307. if (yych >= 'g') { gotoCase = 295; continue; };
  39308. }
  39309. case 298:
  39310. ++cursor;
  39311. yych = this._charAt(cursor);
  39312. if (yych <= '@') {
  39313. if (yych <= '/') { gotoCase = 295; continue; };
  39314. if (yych <= '9') { gotoCase = 292; continue; };
  39315. { gotoCase = 295; continue; };
  39316. } else {
  39317. if (yych <= 'F') { gotoCase = 292; continue; };
  39318. if (yych <= '`') { gotoCase = 295; continue; };
  39319. if (yych <= 'f') { gotoCase = 292; continue; };
  39320. { gotoCase = 295; continue; };
  39321. }
  39322. case 299:
  39323. ++cursor;
  39324. yych = this._charAt(cursor);
  39325. if (yych <= 'e') {
  39326. if (yych <= '\'') {
  39327. if (yych == '"') { gotoCase = 292; continue; };
  39328. if (yych <= '&') { gotoCase = 295; continue; };
  39329. { gotoCase = 292; continue; };
  39330. } else {
  39331. if (yych <= '\\') {
  39332. if (yych <= '[') { gotoCase = 295; continue; };
  39333. { gotoCase = 292; continue; };
  39334. } else {
  39335. if (yych == 'b') { gotoCase = 292; continue; };
  39336. { gotoCase = 295; continue; };
  39337. }
  39338. }
  39339. } else {
  39340. if (yych <= 'r') {
  39341. if (yych <= 'm') {
  39342. if (yych <= 'f') { gotoCase = 292; continue; };
  39343. { gotoCase = 295; continue; };
  39344. } else {
  39345. if (yych <= 'n') { gotoCase = 292; continue; };
  39346. if (yych <= 'q') { gotoCase = 295; continue; };
  39347. { gotoCase = 292; continue; };
  39348. }
  39349. } else {
  39350. if (yych <= 't') {
  39351. if (yych <= 's') { gotoCase = 295; continue; };
  39352. { gotoCase = 292; continue; };
  39353. } else {
  39354. if (yych <= 'u') { gotoCase = 294; continue; };
  39355. if (yych <= 'v') { gotoCase = 292; continue; };
  39356. { gotoCase = 295; continue; };
  39357. }
  39358. }
  39359. }
  39360. case 300:
  39361. ++cursor;
  39362. yych = this._charAt(cursor);
  39363. { gotoCase = 290; continue; };
  39364. }
  39365.  
  39366. }
  39367. },
  39368.  
  39369. __proto__: WebInspector.SourceTokenizer.prototype
  39370. }
  39371.  
  39372.  
  39373.  
  39374.  
  39375.  
  39376.  
  39377. WebInspector.FileSystemModel = function()
  39378. {
  39379. WebInspector.Object.call(this);
  39380.  
  39381. this._originForFrameId = {};
  39382. this._frameIdsForOrigin = {};
  39383. this._fileSystemsForOrigin = {};
  39384.  
  39385. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameAdded, this._frameAdded, this);
  39386. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameNavigated, this._frameNavigated, this);
  39387. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameDetached, this._frameDetached, this);
  39388.  
  39389. FileSystemAgent.enable();
  39390.  
  39391. if (WebInspector.resourceTreeModel.mainFrame)
  39392. this._attachFrameRecursively(WebInspector.resourceTreeModel.mainFrame);
  39393. }
  39394.  
  39395. WebInspector.FileSystemModel.prototype = {
  39396.  
  39397. _frameAdded: function(event)
  39398. {
  39399. var frame =   (event.data);
  39400. this._attachFrameRecursively(frame);
  39401. },
  39402.  
  39403.  
  39404. _frameNavigated: function(event)
  39405. {
  39406. var frame =   (event.data);
  39407. this._attachFrameRecursively(frame);
  39408. },
  39409.  
  39410.  
  39411. _frameDetached: function(event)
  39412. {
  39413. var frame =   (event.data);
  39414. this._detachFrameRecursively(frame);
  39415. },
  39416.  
  39417.  
  39418. _attachFrame: function(frame)
  39419. {
  39420. if (this._originForFrameId[frame.id])
  39421. this._detachFrameRecursively(frame);
  39422.  
  39423. if (frame.securityOrigin === "null")
  39424. return;
  39425.  
  39426. this._originForFrameId[frame.id] = frame.securityOrigin;
  39427.  
  39428. var newOrigin = false;
  39429. if (!this._frameIdsForOrigin[frame.securityOrigin]) {
  39430. this._frameIdsForOrigin[frame.securityOrigin] = {};
  39431. newOrigin = true;
  39432. }
  39433. this._frameIdsForOrigin[frame.securityOrigin][frame.id] = frame.id;
  39434. if (newOrigin)
  39435. this._originAdded(frame.securityOrigin);
  39436. },
  39437.  
  39438.  
  39439. _attachFrameRecursively: function(frame)
  39440. {
  39441. this._attachFrame(frame);
  39442. for (var i = 0; i < frame.childFrames.length; ++i)
  39443. this._attachFrameRecursively(frame.childFrames[i]);
  39444. },
  39445.  
  39446.  
  39447. _detachFrame: function(frame)
  39448. {
  39449. if (!this._originForFrameId[frame.id])
  39450. return;
  39451. var origin = this._originForFrameId[frame.id];
  39452. delete this._originForFrameId[frame.id];
  39453. delete this._frameIdsForOrigin[origin][frame.id];
  39454.  
  39455. var lastOrigin = Object.isEmpty(this._frameIdsForOrigin[origin]);
  39456. if (lastOrigin) {
  39457. delete this._frameIdsForOrigin[origin];
  39458. this._originRemoved(origin);
  39459. }
  39460. },
  39461.  
  39462.  
  39463. _detachFrameRecursively: function(frame)
  39464. {
  39465. for (var i = 0; i < frame.childFrames.length; ++i)
  39466. this._detachFrameRecursively(frame.childFrames[i]);
  39467. this._detachFrame(frame);
  39468. },
  39469.  
  39470.  
  39471. _originAdded: function(origin)
  39472. {
  39473. this._fileSystemsForOrigin[origin] = {};
  39474.  
  39475. var types = ["persistent", "temporary"];
  39476. for (var i = 0; i < types.length; ++i)
  39477. this._requestFileSystemRoot(origin, types[i], this._fileSystemRootReceived.bind(this, origin, types[i], this._fileSystemsForOrigin[origin]));
  39478. },
  39479.  
  39480.  
  39481. _requestFileSystemRoot: function(origin, type, callback)
  39482. {
  39483.  
  39484. function innerCallback(error, errorCode, backendRootEntry)
  39485. {
  39486. if (error) {
  39487. callback(FileError.SECURITY_ERR);
  39488. return;
  39489. }
  39490.  
  39491. callback(errorCode, backendRootEntry);
  39492. }
  39493.  
  39494. FileSystemAgent.requestFileSystemRoot(origin, type, innerCallback.bind(this));
  39495. },
  39496.  
  39497.  
  39498. _originRemoved: function(origin)
  39499. {
  39500. for (var type in this._fileSystemsForOrigin[origin]) {
  39501. var fileSystem = this._fileSystemsForOrigin[origin][type];
  39502. delete this._fileSystemsForOrigin[origin][type];
  39503. this._fileSystemRemoved(fileSystem);
  39504. }
  39505. delete this._fileSystemsForOrigin[origin];
  39506. },
  39507.  
  39508.  
  39509. _fileSystemAdded: function(fileSystem)
  39510. {
  39511. this.dispatchEventToListeners(WebInspector.FileSystemModel.EventTypes.FileSystemAdded, fileSystem);
  39512. },
  39513.  
  39514.  
  39515. _fileSystemRemoved: function(fileSystem)
  39516. {
  39517. this.dispatchEventToListeners(WebInspector.FileSystemModel.EventTypes.FileSystemRemoved, fileSystem);
  39518. },
  39519.  
  39520. refreshFileSystemList: function()
  39521. {
  39522. if (WebInspector.resourceTreeModel.mainFrame) {
  39523. this._detachFrameRecursively(WebInspector.resourceTreeModel.mainFrame);
  39524. this._attachFrameRecursively(WebInspector.resourceTreeModel.mainFrame);
  39525. }
  39526. },
  39527.  
  39528.  
  39529. _fileSystemRootReceived: function(origin, type, store, errorCode, backendRootEntry)
  39530. {
  39531. if (!errorCode && backendRootEntry && this._fileSystemsForOrigin[origin] === store) {
  39532. var fileSystem = new WebInspector.FileSystemModel.FileSystem(this, origin, type, backendRootEntry);
  39533. store[type] = fileSystem;
  39534. this._fileSystemAdded(fileSystem);
  39535. }
  39536. },
  39537.  
  39538.  
  39539. requestDirectoryContent: function(directory, callback)
  39540. {
  39541. this._requestDirectoryContent(directory.url, this._directoryContentReceived.bind(this, directory, callback));
  39542. },
  39543.  
  39544.  
  39545. _requestDirectoryContent: function(url, callback)
  39546. {
  39547.  
  39548. function innerCallback(error, errorCode, backendEntries)
  39549. {
  39550. if (error) {
  39551. callback(FileError.SECURITY_ERR);
  39552. return;
  39553. }
  39554.  
  39555. if (errorCode !== 0) {
  39556. callback(errorCode, null);
  39557. return;
  39558. }
  39559.  
  39560. callback(errorCode, backendEntries);
  39561. }
  39562.  
  39563. FileSystemAgent.requestDirectoryContent(url, innerCallback.bind(this));
  39564. },
  39565.  
  39566.  
  39567. _directoryContentReceived: function(parentDirectory, callback, errorCode, backendEntries)
  39568. {
  39569. var entries = [];
  39570. for (var i = 0; i < backendEntries.length; ++i) {
  39571. if (backendEntries[i].isDirectory)
  39572. entries.push(new WebInspector.FileSystemModel.Directory(this, parentDirectory.fileSystem, backendEntries[i]));
  39573. else
  39574. entries.push(new WebInspector.FileSystemModel.File(this, parentDirectory.fileSystem, backendEntries[i]));
  39575. }
  39576.  
  39577. callback(errorCode, entries);
  39578. },
  39579.  
  39580.  
  39581. requestMetadata: function(entry, callback)
  39582. {
  39583.  
  39584. function innerCallback(error, errorCode, metadata)
  39585. {
  39586. if (error) {
  39587. callback(FileError.SECURITY_ERR);
  39588. return;
  39589. }
  39590.  
  39591. callback(errorCode, metadata);
  39592. }
  39593.  
  39594. FileSystemAgent.requestMetadata(entry.url, innerCallback.bind(this));
  39595. },
  39596.  
  39597.  
  39598. requestFileContent: function(file, readAsText, start, end, charset, callback)
  39599. {
  39600. this._requestFileContent(file.url, readAsText, start, end, charset, callback);
  39601. },
  39602.  
  39603.  
  39604. _requestFileContent: function(url, readAsText, start, end, charset, callback)
  39605. {
  39606.  
  39607. function innerCallback(error, errorCode, content, charset)
  39608. {
  39609. if (error) {
  39610. if (callback)
  39611. callback(FileError.SECURITY_ERR);
  39612. return;
  39613. }
  39614.  
  39615. if (callback)
  39616. callback(errorCode, content, charset);
  39617. }
  39618.  
  39619. FileSystemAgent.requestFileContent(url, readAsText, start, end, charset, innerCallback.bind(this));
  39620. },
  39621.  
  39622. deleteEntry: function(entry, callback)
  39623. {
  39624. var fileSystemModel = this;
  39625. if (entry === entry.fileSystem.root)
  39626. this._deleteEntry(entry.url, hookFileSystemDeletion);
  39627. else
  39628. this._deleteEntry(entry.url, callback);
  39629.  
  39630. function hookFileSystemDeletion(errorCode)
  39631. {
  39632. callback(errorCode);
  39633. if (!errorCode)
  39634. fileSystemModel._removeFileSystem(entry.fileSystem);
  39635. }
  39636. },
  39637.  
  39638.  
  39639. _deleteEntry: function(url, callback)
  39640. {
  39641.  
  39642. function innerCallback(error, errorCode)
  39643. {
  39644. if (error) {
  39645. if (callback)
  39646. callback(FileError.SECURITY_ERR);
  39647. return;
  39648. }
  39649.  
  39650. if (callback)
  39651. callback(errorCode);
  39652. }
  39653.  
  39654. FileSystemAgent.deleteEntry(url, innerCallback.bind(this));
  39655. },
  39656.  
  39657.  
  39658. _removeFileSystem: function(fileSystem)
  39659. {
  39660. var origin = fileSystem.origin;
  39661. var type = fileSystem.type;
  39662. if (this._fileSystemsForOrigin[origin] && this._fileSystemsForOrigin[origin][type]) {
  39663. delete this._fileSystemsForOrigin[origin][type];
  39664. this._fileSystemRemoved(fileSystem);
  39665.  
  39666. if (Object.isEmpty(this._fileSystemsForOrigin[origin]))
  39667. delete this._fileSystemsForOrigin[origin];
  39668. }
  39669. },
  39670.  
  39671. __proto__: WebInspector.Object.prototype
  39672. }
  39673.  
  39674.  
  39675. WebInspector.FileSystemModel.EventTypes = {
  39676. FileSystemAdded: "FileSystemAdded",
  39677. FileSystemRemoved: "FileSystemRemoved"
  39678. }
  39679.  
  39680.  
  39681. WebInspector.FileSystemModel.FileSystem = function(fileSystemModel, origin, type, backendRootEntry)
  39682. {
  39683. this.origin = origin;
  39684. this.type = type;
  39685.  
  39686. this.root = new WebInspector.FileSystemModel.Directory(fileSystemModel, this, backendRootEntry);
  39687. }
  39688.  
  39689. WebInspector.FileSystemModel.FileSystem.prototype = {
  39690.  
  39691. get name()
  39692. {
  39693. return "filesystem:" + this.origin + "/" + this.type;
  39694. }
  39695. }
  39696.  
  39697.  
  39698. WebInspector.FileSystemModel.Entry = function(fileSystemModel, fileSystem, backendEntry)
  39699. {
  39700. this._fileSystemModel = fileSystemModel;
  39701. this._fileSystem = fileSystem;
  39702.  
  39703. this._url = backendEntry.url;
  39704. this._name = backendEntry.name;
  39705. this._isDirectory = backendEntry.isDirectory;
  39706. }
  39707.  
  39708.  
  39709. WebInspector.FileSystemModel.Entry.compare = function(x, y)
  39710. {
  39711. if (x.isDirectory != y.isDirectory)
  39712. return y.isDirectory ? 1 : -1;
  39713. return x.name.localeCompare(y.name);
  39714. }
  39715.  
  39716. WebInspector.FileSystemModel.Entry.prototype = {
  39717.  
  39718. get fileSystemModel()
  39719. {
  39720. return this._fileSystemModel;
  39721. },
  39722.  
  39723.  
  39724. get fileSystem()
  39725. {
  39726. return this._fileSystem;
  39727. },
  39728.  
  39729.  
  39730. get url()
  39731. {
  39732. return this._url;
  39733. },
  39734.  
  39735.  
  39736. get name()
  39737. {
  39738. return this._name;
  39739. },
  39740.  
  39741.  
  39742. get isDirectory()
  39743. {
  39744. return this._isDirectory;
  39745. },
  39746.  
  39747.  
  39748. requestMetadata: function(callback)
  39749. {
  39750. this.fileSystemModel.requestMetadata(this, callback);
  39751. },
  39752.  
  39753.  
  39754. deleteEntry: function(callback)
  39755. {
  39756. this.fileSystemModel.deleteEntry(this, callback);
  39757. }
  39758. }
  39759.  
  39760.  
  39761. WebInspector.FileSystemModel.Directory = function(fileSystemModel, fileSystem, backendEntry)
  39762. {
  39763. WebInspector.FileSystemModel.Entry.call(this, fileSystemModel, fileSystem, backendEntry);
  39764. }
  39765.  
  39766. WebInspector.FileSystemModel.Directory.prototype = {
  39767.  
  39768. requestDirectoryContent: function(callback)
  39769. {
  39770. this.fileSystemModel.requestDirectoryContent(this, callback);
  39771. },
  39772.  
  39773. __proto__: WebInspector.FileSystemModel.Entry.prototype
  39774. }
  39775.  
  39776.  
  39777. WebInspector.FileSystemModel.File = function(fileSystemModel, fileSystem, backendEntry)
  39778. {
  39779. WebInspector.FileSystemModel.Entry.call(this, fileSystemModel, fileSystem, backendEntry);
  39780.  
  39781. this._mimeType = backendEntry.mimeType;
  39782. this._resourceType = WebInspector.resourceTypes[backendEntry.resourceType];
  39783. this._isTextFile = backendEntry.isTextFile;
  39784. }
  39785.  
  39786. WebInspector.FileSystemModel.File.prototype = {
  39787.  
  39788. get mimeType()
  39789. {
  39790. return this._mimeType;
  39791. },
  39792.  
  39793.  
  39794. get resourceType()
  39795. {
  39796. return this._resourceType;
  39797. },
  39798.  
  39799.  
  39800. get isTextFile()
  39801. {
  39802. return this._isTextFile;
  39803. },
  39804.  
  39805.  
  39806. requestFileContent: function(readAsText, start, end, charset, callback)
  39807. {
  39808. this.fileSystemModel.requestFileContent(this, readAsText, start, end, charset, callback);
  39809. },
  39810.  
  39811. __proto__: WebInspector.FileSystemModel.Entry.prototype
  39812. }
  39813.  
  39814.  
  39815.  
  39816.  
  39817.  
  39818.  
  39819. WebInspector.OutputStreamDelegate = function()
  39820. {
  39821. }
  39822.  
  39823. WebInspector.OutputStreamDelegate.prototype = {
  39824. onTransferStarted: function() { },
  39825.  
  39826. onTransferFinished: function() { },
  39827.  
  39828.  
  39829. onChunkTransferred: function(reader) { },
  39830.  
  39831.  
  39832. onError: function(reader, event) { },
  39833. }
  39834.  
  39835.  
  39836. WebInspector.OutputStream = function()
  39837. {
  39838. }
  39839.  
  39840. WebInspector.OutputStream.prototype = {
  39841.  
  39842. write: function(data, callback) { },
  39843.  
  39844. close: function() { }
  39845. }
  39846.  
  39847.  
  39848. WebInspector.ChunkedReader = function()
  39849. {
  39850. }
  39851.  
  39852. WebInspector.ChunkedReader.prototype = {
  39853.  
  39854. fileSize: function() { },
  39855.  
  39856.  
  39857. loadedSize: function() { },
  39858.  
  39859.  
  39860. fileName: function() { },
  39861.  
  39862. cancel: function() { }
  39863. }
  39864.  
  39865.  
  39866. WebInspector.ChunkedFileReader = function(file, chunkSize, delegate)
  39867. {
  39868. this._file = file;
  39869. this._fileSize = file.size;
  39870. this._loadedSize = 0;
  39871. this._chunkSize = chunkSize;
  39872. this._delegate = delegate;
  39873. this._isCanceled = false;
  39874. }
  39875.  
  39876. WebInspector.ChunkedFileReader.prototype = {
  39877.  
  39878. start: function(output)
  39879. {
  39880. this._output = output;
  39881.  
  39882. this._reader = new FileReader();
  39883. this._reader.onload = this._onChunkLoaded.bind(this);
  39884. this._reader.onerror = this._delegate.onError.bind(this._delegate, this);
  39885. this._delegate.onTransferStarted();
  39886. this._loadChunk();
  39887. },
  39888.  
  39889. cancel: function()
  39890. {
  39891. this._isCanceled = true;
  39892. },
  39893.  
  39894.  
  39895. loadedSize: function()
  39896. {
  39897. return this._loadedSize;
  39898. },
  39899.  
  39900.  
  39901. fileSize: function()
  39902. {
  39903. return this._fileSize;
  39904. },
  39905.  
  39906.  
  39907. fileName: function()
  39908. {
  39909. return this._file.name;
  39910. },
  39911.  
  39912.  
  39913. _onChunkLoaded: function(event)
  39914. {
  39915. if (this._isCanceled)
  39916. return;
  39917.  
  39918. if (event.target.readyState !== FileReader.DONE)
  39919. return;
  39920.  
  39921. var data = event.target.result;
  39922. this._loadedSize += data.length;
  39923.  
  39924. this._output.write(data);
  39925. if (this._isCanceled)
  39926. return;
  39927. this._delegate.onChunkTransferred(this);
  39928.  
  39929. if (this._loadedSize === this._fileSize) {
  39930. this._file = null;
  39931. this._reader = null;
  39932. this._output.close();
  39933. this._delegate.onTransferFinished();
  39934. return;
  39935. }
  39936.  
  39937. this._loadChunk();
  39938. },
  39939.  
  39940. _loadChunk: function()
  39941. {
  39942. var chunkStart = this._loadedSize;
  39943. var chunkEnd = Math.min(this._fileSize, chunkStart + this._chunkSize)
  39944. var nextPart = this._file.slice(chunkStart, chunkEnd);
  39945. this._reader.readAsText(nextPart);
  39946. }
  39947. }
  39948.  
  39949.  
  39950. WebInspector.ChunkedXHRReader = function(url, delegate)
  39951. {
  39952. this._url = url;
  39953. this._delegate = delegate;
  39954. this._fileSize = 0;
  39955. this._loadedSize = 0;
  39956. this._isCanceled = false;
  39957. }
  39958.  
  39959. WebInspector.ChunkedXHRReader.prototype = {
  39960.  
  39961. start: function(output)
  39962. {
  39963. this._output = output;
  39964.  
  39965. this._xhr = new XMLHttpRequest();
  39966. this._xhr.open("GET", this._url, true);
  39967. this._xhr.onload = this._onLoad.bind(this);
  39968. this._xhr.onprogress = this._onProgress.bind(this);
  39969. this._xhr.onerror = this._delegate.onError.bind(this._delegate, this);
  39970. this._xhr.send(null);
  39971.  
  39972. this._delegate.onTransferStarted();
  39973. },
  39974.  
  39975. cancel: function()
  39976. {
  39977. this._isCanceled = true;
  39978. this._xhr.abort();
  39979. },
  39980.  
  39981.  
  39982. loadedSize: function()
  39983. {
  39984. return this._loadedSize;
  39985. },
  39986.  
  39987.  
  39988. fileSize: function()
  39989. {
  39990. return this._fileSize;
  39991. },
  39992.  
  39993.  
  39994. fileName: function()
  39995. {
  39996. return this._url;
  39997. },
  39998.  
  39999.  
  40000. _onProgress: function(event)
  40001. {
  40002. if (this._isCanceled)
  40003. return;
  40004.  
  40005. if (event.lengthComputable)
  40006. this._fileSize = event.total;
  40007.  
  40008. var data = this._xhr.responseText.substring(this._loadedSize);
  40009. if (!data.length)
  40010. return;
  40011.  
  40012. this._loadedSize += data.length;
  40013. this._output.write(data);
  40014. if (this._isCanceled)
  40015. return;
  40016. this._delegate.onChunkTransferred(this);
  40017. },
  40018.  
  40019.  
  40020. _onLoad: function(event)
  40021. {
  40022. this._onProgress(event);
  40023.  
  40024. if (this._isCanceled)
  40025. return;
  40026.  
  40027. this._output.close();
  40028. this._delegate.onTransferFinished();
  40029. }
  40030. }
  40031.  
  40032.  
  40033. WebInspector.createFileSelectorElement = function(callback) {
  40034. var fileSelectorElement = document.createElement("input");
  40035. fileSelectorElement.type = "file";
  40036. fileSelectorElement.style.zIndex = -1;
  40037. fileSelectorElement.style.position = "absolute";
  40038. fileSelectorElement.onchange = function(event) {
  40039. callback(fileSelectorElement.files[0]);
  40040. };
  40041. return fileSelectorElement;
  40042. }
  40043.  
  40044.  
  40045. WebInspector.findBalancedCurlyBrackets = function(source, startIndex, lastIndex) {
  40046. lastIndex = lastIndex || source.length;
  40047. startIndex = startIndex || 0;
  40048. var counter = 0;
  40049. var inString = false;
  40050.  
  40051. for (var index = startIndex; index < lastIndex; ++index) {
  40052. var character = source[index];
  40053. if (inString) {
  40054. if (character === "\\")
  40055. ++index;
  40056. else if (character === "\"")
  40057. inString = false;
  40058. } else {
  40059. if (character === "\"")
  40060. inString = true;
  40061. else if (character === "{")
  40062. ++counter;
  40063. else if (character === "}") {
  40064. if (--counter === 0)
  40065. return index + 1;
  40066. }
  40067. }
  40068. }
  40069. return -1;
  40070. }
  40071.  
  40072.  
  40073. WebInspector.FileOutputStream = function()
  40074. {
  40075. }
  40076.  
  40077. WebInspector.FileOutputStream.prototype = {
  40078.  
  40079. open: function(fileName, callback)
  40080. {
  40081. this._closed = false;
  40082. this._writeCallbacks = [];
  40083. this._fileName = fileName;
  40084. function callbackWrapper()
  40085. {
  40086. WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.SavedURL, callbackWrapper, this);
  40087. WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._onAppendDone, this);
  40088. callback(this);
  40089. }
  40090. WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.SavedURL, callbackWrapper, this);
  40091. WebInspector.fileManager.save(this._fileName, "", true);
  40092. },
  40093.  
  40094.  
  40095. write: function(data, callback)
  40096. {
  40097. this._writeCallbacks.push(callback);
  40098. WebInspector.fileManager.append(this._fileName, data);
  40099. },
  40100.  
  40101. close: function()
  40102. {
  40103. this._closed = true;
  40104. if (this._writeCallbacks.length)
  40105. return;
  40106. WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._onAppendDone, this);
  40107. WebInspector.fileManager.close(this._fileName);
  40108. },
  40109.  
  40110.  
  40111. _onAppendDone: function(event)
  40112. {
  40113. if (event.data !== this._fileName)
  40114. return;
  40115. if (!this._writeCallbacks.length) {
  40116. if (this._closed) {
  40117. WebInspector.fileManager.removeEventListener(WebInspector.FileManager.EventTypes.AppendedToURL, this._onAppendDone, this);
  40118. WebInspector.fileManager.close(this._fileName);
  40119. }
  40120. return;
  40121. }
  40122. var callback = this._writeCallbacks.shift();
  40123. if (callback)
  40124. callback(this);
  40125. }
  40126. }
  40127.  
  40128.  
  40129.  
  40130.  
  40131.  
  40132.  
  40133. WebInspector.DebuggerModel = function()
  40134. {
  40135. InspectorBackend.registerDebuggerDispatcher(new WebInspector.DebuggerDispatcher(this));
  40136.  
  40137. this._debuggerPausedDetails = null;
  40138.  
  40139. this._scripts = {};
  40140. this._scriptsBySourceURL = {};
  40141.  
  40142. this._canSetScriptSource = false;
  40143. this._breakpointsActive = true;
  40144.  
  40145. WebInspector.settings.pauseOnExceptionStateString = WebInspector.settings.createSetting("pauseOnExceptionStateString", WebInspector.DebuggerModel.PauseOnExceptionsState.DontPauseOnExceptions);
  40146. WebInspector.settings.pauseOnExceptionStateString.addChangeListener(this._pauseOnExceptionStateChanged, this);
  40147.  
  40148. if (!Capabilities.debuggerCausesRecompilation || WebInspector.settings.debuggerEnabled.get())
  40149. this.enableDebugger();
  40150. }
  40151.  
  40152.  
  40153. WebInspector.DebuggerModel.PauseOnExceptionsState = {
  40154. DontPauseOnExceptions : "none",
  40155. PauseOnAllExceptions : "all",
  40156. PauseOnUncaughtExceptions: "uncaught"
  40157. };
  40158.  
  40159.  
  40160. WebInspector.DebuggerModel.Location = function(scriptId, lineNumber, columnNumber)
  40161. {
  40162. this.scriptId = scriptId;
  40163. this.lineNumber = lineNumber;
  40164. this.columnNumber = columnNumber;
  40165. }
  40166.  
  40167. WebInspector.DebuggerModel.Events = {
  40168. DebuggerWasEnabled: "DebuggerWasEnabled",
  40169. DebuggerWasDisabled: "DebuggerWasDisabled",
  40170. DebuggerPaused: "DebuggerPaused",
  40171. DebuggerResumed: "DebuggerResumed",
  40172. ParsedScriptSource: "ParsedScriptSource",
  40173. FailedToParseScriptSource: "FailedToParseScriptSource",
  40174. BreakpointResolved: "BreakpointResolved",
  40175. GlobalObjectCleared: "GlobalObjectCleared",
  40176. CallFrameSelected: "CallFrameSelected",
  40177. ExecutionLineChanged: "ExecutionLineChanged",
  40178. ConsoleCommandEvaluatedInSelectedCallFrame: "ConsoleCommandEvaluatedInSelectedCallFrame",
  40179. BreakpointsActiveStateChanged: "BreakpointsActiveStateChanged"
  40180. }
  40181.  
  40182. WebInspector.DebuggerModel.BreakReason = {
  40183. DOM: "DOM",
  40184. EventListener: "EventListener",
  40185. XHR: "XHR",
  40186. Exception: "exception",
  40187. Assert: "assert",
  40188. CSPViolation: "CSPViolation"
  40189. }
  40190.  
  40191. WebInspector.DebuggerModel.prototype = {
  40192.  
  40193. debuggerEnabled: function()
  40194. {
  40195. return !!this._debuggerEnabled;
  40196. },
  40197.  
  40198. enableDebugger: function()
  40199. {
  40200. if (this._debuggerEnabled)
  40201. return;
  40202.  
  40203. function callback(error, result)
  40204. {
  40205. this._canSetScriptSource = result;
  40206. }
  40207. DebuggerAgent.canSetScriptSource(callback.bind(this));
  40208. DebuggerAgent.enable(this._debuggerWasEnabled.bind(this));
  40209. },
  40210.  
  40211. disableDebugger: function()
  40212. {
  40213. if (!this._debuggerEnabled)
  40214. return;
  40215.  
  40216. DebuggerAgent.disable(this._debuggerWasDisabled.bind(this));
  40217. },
  40218.  
  40219.  
  40220. canSetScriptSource: function()
  40221. {
  40222. return this._canSetScriptSource;
  40223. },
  40224.  
  40225. _debuggerWasEnabled: function()
  40226. {
  40227. this._debuggerEnabled = true;
  40228. this._pauseOnExceptionStateChanged();
  40229. this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.DebuggerWasEnabled);
  40230. },
  40231.  
  40232. _pauseOnExceptionStateChanged: function()
  40233. {
  40234. DebuggerAgent.setPauseOnExceptions(WebInspector.settings.pauseOnExceptionStateString.get());
  40235. },
  40236.  
  40237. _debuggerWasDisabled: function()
  40238. {
  40239. this._debuggerEnabled = false;
  40240. this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.DebuggerWasDisabled);
  40241. },
  40242.  
  40243.  
  40244. continueToLocation: function(rawLocation)
  40245. {
  40246. DebuggerAgent.continueToLocation(rawLocation);
  40247. },
  40248.  
  40249.  
  40250. setBreakpointByScriptLocation: function(rawLocation, condition, callback)
  40251. {
  40252. var script = this.scriptForId(rawLocation.scriptId);
  40253. if (script.sourceURL)
  40254. this.setBreakpointByURL(script.sourceURL, rawLocation.lineNumber, rawLocation.columnNumber, condition, callback);
  40255. else
  40256. this.setBreakpointBySourceId(rawLocation, condition, callback);
  40257. },
  40258.  
  40259.  
  40260. setBreakpointByURL: function(url, lineNumber, columnNumber, condition, callback)
  40261. {
  40262.  
  40263. var minColumnNumber = 0;
  40264. var scripts = this._scriptsBySourceURL[url] || [];
  40265. for (var i = 0, l = scripts.length; i < l; ++i) {
  40266. var script = scripts[i];
  40267. if (lineNumber === script.lineOffset)
  40268. minColumnNumber = minColumnNumber ? Math.min(minColumnNumber, script.columnOffset) : script.columnOffset;
  40269. }
  40270. columnNumber = Math.max(columnNumber, minColumnNumber);
  40271.  
  40272.  
  40273. function didSetBreakpoint(error, breakpointId, locations)
  40274. {
  40275. if (callback) {
  40276. var rawLocations =   (locations);
  40277. callback(error ? null : breakpointId, rawLocations);
  40278. }
  40279. }
  40280. DebuggerAgent.setBreakpointByUrl(lineNumber, url, undefined, columnNumber, condition, didSetBreakpoint.bind(this));
  40281. WebInspector.userMetrics.ScriptsBreakpointSet.record();
  40282. },
  40283.  
  40284.  
  40285. setBreakpointBySourceId: function(rawLocation, condition, callback)
  40286. {
  40287.  
  40288. function didSetBreakpoint(error, breakpointId, actualLocation)
  40289. {
  40290. if (callback) {
  40291. var rawLocation =   (actualLocation);
  40292. callback(error ? null : breakpointId, [rawLocation]);
  40293. }
  40294. }
  40295. DebuggerAgent.setBreakpoint(rawLocation, condition, didSetBreakpoint.bind(this));
  40296. WebInspector.userMetrics.ScriptsBreakpointSet.record();
  40297. },
  40298.  
  40299.  
  40300. removeBreakpoint: function(breakpointId, callback)
  40301. {
  40302. DebuggerAgent.removeBreakpoint(breakpointId, callback);
  40303. },
  40304.  
  40305.  
  40306. _breakpointResolved: function(breakpointId, location)
  40307. {
  40308. this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.BreakpointResolved, {breakpointId: breakpointId, location: location});
  40309. },
  40310.  
  40311. _globalObjectCleared: function()
  40312. {
  40313. this._setDebuggerPausedDetails(null);
  40314. this._reset();
  40315. this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.GlobalObjectCleared);
  40316. },
  40317.  
  40318. _reset: function()
  40319. {
  40320. this._scripts = {};
  40321. this._scriptsBySourceURL = {};
  40322. },
  40323.  
  40324.  
  40325. get scripts()
  40326. {
  40327. return this._scripts;
  40328. },
  40329.  
  40330.  
  40331. scriptForId: function(scriptId)
  40332. {
  40333. return this._scripts[scriptId] || null;
  40334. },
  40335.  
  40336.  
  40337. setScriptSource: function(scriptId, newSource, callback)
  40338. {
  40339. this._scripts[scriptId].editSource(newSource, this._didEditScriptSource.bind(this, scriptId, newSource, callback));
  40340. },
  40341.  
  40342.  
  40343. _didEditScriptSource: function(scriptId, newSource, callback, error, callFrames)
  40344. {
  40345. callback(error);
  40346. if (!error && callFrames && callFrames.length)
  40347. this._pausedScript(callFrames, this._debuggerPausedDetails.reason, this._debuggerPausedDetails.auxData);
  40348. },
  40349.  
  40350.  
  40351. get callFrames()
  40352. {
  40353. return this._debuggerPausedDetails ? this._debuggerPausedDetails.callFrames : null;
  40354. },
  40355.  
  40356.  
  40357. debuggerPausedDetails: function()
  40358. {
  40359. return this._debuggerPausedDetails;
  40360. },
  40361.  
  40362.  
  40363. _setDebuggerPausedDetails: function(debuggerPausedDetails)
  40364. {
  40365. if (this._debuggerPausedDetails)
  40366. this._debuggerPausedDetails.dispose();
  40367. this._debuggerPausedDetails = debuggerPausedDetails;
  40368. if (this._debuggerPausedDetails)
  40369. this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.DebuggerPaused, this._debuggerPausedDetails);
  40370. if (debuggerPausedDetails) {
  40371. this.setSelectedCallFrame(debuggerPausedDetails.callFrames[0]);
  40372. DebuggerAgent.setOverlayMessage(WebInspector.UIString("Paused in debugger"));
  40373. } else {
  40374. this.setSelectedCallFrame(null);
  40375. DebuggerAgent.setOverlayMessage();
  40376. }
  40377. },
  40378.  
  40379.  
  40380. _pausedScript: function(callFrames, reason, auxData)
  40381. {
  40382. this._setDebuggerPausedDetails(new WebInspector.DebuggerPausedDetails(this, callFrames, reason, auxData));
  40383. },
  40384.  
  40385. _resumedScript: function()
  40386. {
  40387. this._setDebuggerPausedDetails(null);
  40388. if (this._executionLineLiveLocation)
  40389. this._executionLineLiveLocation.dispose();
  40390. this._executionLineLiveLocation = null;
  40391. this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.DebuggerResumed);
  40392. },
  40393.  
  40394.  
  40395. _parsedScriptSource: function(scriptId, sourceURL, startLine, startColumn, endLine, endColumn, isContentScript, sourceMapURL, hasSourceURL)
  40396. {
  40397. var script = new WebInspector.Script(scriptId, sourceURL, startLine, startColumn, endLine, endColumn, isContentScript, sourceMapURL, hasSourceURL);
  40398. this._registerScript(script);
  40399. this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.ParsedScriptSource, script);
  40400. },
  40401.  
  40402.  
  40403. _registerScript: function(script)
  40404. {
  40405. this._scripts[script.scriptId] = script;
  40406. if (script.sourceURL) {
  40407. var scripts = this._scriptsBySourceURL[script.sourceURL];
  40408. if (!scripts) {
  40409. scripts = [];
  40410. this._scriptsBySourceURL[script.sourceURL] = scripts;
  40411. }
  40412. scripts.push(script);
  40413. }
  40414. },
  40415.  
  40416.  
  40417. createRawLocation: function(script, lineNumber, columnNumber)
  40418. {
  40419. if (script.sourceURL)
  40420. return this.createRawLocationByURL(script.sourceURL, lineNumber, columnNumber)
  40421. return new WebInspector.DebuggerModel.Location(script.scriptId, lineNumber, columnNumber);
  40422. },
  40423.  
  40424.  
  40425. createRawLocationByURL: function(sourceURL, lineNumber, columnNumber)
  40426. {
  40427. var closestScript = null;
  40428. var scripts = this._scriptsBySourceURL[sourceURL] || [];
  40429. for (var i = 0, l = scripts.length; i < l; ++i) {
  40430. var script = scripts[i];
  40431. if (!closestScript)
  40432. closestScript = script;
  40433. if (script.lineOffset > lineNumber || (script.lineOffset === lineNumber && script.columnOffset > columnNumber))
  40434. continue;
  40435. if (script.endLine < lineNumber || (script.endLine === lineNumber && script.endColumn <= columnNumber))
  40436. continue;
  40437. closestScript = script;
  40438. break;
  40439. }
  40440. return closestScript ? new WebInspector.DebuggerModel.Location(closestScript.scriptId, lineNumber, columnNumber) : null;
  40441. },
  40442.  
  40443.  
  40444. isPaused: function()
  40445. {
  40446. return !!this.debuggerPausedDetails();
  40447. },
  40448.  
  40449.  
  40450. setSelectedCallFrame: function(callFrame)
  40451. {
  40452. if (this._executionLineLiveLocation)
  40453. this._executionLineLiveLocation.dispose();
  40454. delete this._executionLineLiveLocation;
  40455.  
  40456. this._selectedCallFrame = callFrame;
  40457. if (!this._selectedCallFrame)
  40458. return;
  40459.  
  40460. this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.CallFrameSelected, callFrame);
  40461.  
  40462. function updateExecutionLine(uiLocation)
  40463. {
  40464. this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.ExecutionLineChanged, uiLocation);
  40465. }
  40466. this._executionLineLiveLocation = callFrame.script.createLiveLocation(callFrame.location, updateExecutionLine.bind(this));
  40467. },
  40468.  
  40469.  
  40470. selectedCallFrame: function()
  40471. {
  40472. return this._selectedCallFrame;
  40473. },
  40474.  
  40475.  
  40476. evaluateOnSelectedCallFrame: function(code, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, callback)
  40477. {
  40478.  
  40479. function didEvaluate(result, wasThrown)
  40480. {
  40481. if (returnByValue)
  40482. callback(null, !!wasThrown, wasThrown ? null : result);
  40483. else
  40484. callback(WebInspector.RemoteObject.fromPayload(result), !!wasThrown);
  40485.  
  40486. if (objectGroup === "console")
  40487. this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.ConsoleCommandEvaluatedInSelectedCallFrame);
  40488. }
  40489.  
  40490. this.selectedCallFrame().evaluate(code, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, didEvaluate.bind(this));
  40491. },
  40492.  
  40493.  
  40494. getSelectedCallFrameVariables: function(callback)
  40495. {
  40496. var result = { this: true };
  40497.  
  40498. var selectedCallFrame = this._selectedCallFrame;
  40499. if (!selectedCallFrame)
  40500. callback(result);
  40501.  
  40502. var pendingRequests = 0;
  40503.  
  40504. function propertiesCollected(properties)
  40505. {
  40506. for (var i = 0; properties && i < properties.length; ++i)
  40507. result[properties[i].name] = true;
  40508. if (--pendingRequests == 0)
  40509. callback(result);
  40510. }
  40511.  
  40512. for (var i = 0; i < selectedCallFrame.scopeChain.length; ++i) {
  40513. var scope = selectedCallFrame.scopeChain[i];
  40514. var object = WebInspector.RemoteObject.fromPayload(scope.object);
  40515. pendingRequests++;
  40516. object.getAllProperties(propertiesCollected);
  40517. }
  40518. },
  40519.  
  40520.  
  40521. setBreakpointsActive: function(active)
  40522. {
  40523. if (this._breakpointsActive === active)
  40524. return;
  40525. this._breakpointsActive = active;
  40526. DebuggerAgent.setBreakpointsActive(active);
  40527. this.dispatchEventToListeners(WebInspector.DebuggerModel.Events.BreakpointsActiveStateChanged, active);
  40528. },
  40529.  
  40530.  
  40531. breakpointsActive: function()
  40532. {
  40533. return this._breakpointsActive;
  40534. },
  40535.  
  40536.  
  40537. createLiveLocation: function(rawLocation, updateDelegate)
  40538. {
  40539. var script = this._scripts[rawLocation.scriptId];
  40540. return script.createLiveLocation(rawLocation, updateDelegate);
  40541. },
  40542.  
  40543.  
  40544. rawLocationToUILocation: function(rawLocation)
  40545. {
  40546. var script = this._scripts[rawLocation.scriptId];
  40547. if (!script)
  40548. return null;
  40549. return script.rawLocationToUILocation(rawLocation.lineNumber, rawLocation.columnNumber);
  40550. },
  40551.  
  40552.  
  40553. callStackModified: function(newCallFrames, details)
  40554. {
  40555.  
  40556. if (details && details["stack_update_needs_step_in"])
  40557. DebuggerAgent.stepInto();
  40558. else {
  40559. if (newCallFrames && newCallFrames.length)
  40560. this._pausedScript(newCallFrames, this._debuggerPausedDetails.reason, this._debuggerPausedDetails.auxData);
  40561.  
  40562. }
  40563. },
  40564.  
  40565. __proto__: WebInspector.Object.prototype
  40566. }
  40567.  
  40568. WebInspector.DebuggerEventTypes = {
  40569. JavaScriptPause: 0,
  40570. JavaScriptBreakpoint: 1,
  40571. NativeBreakpoint: 2
  40572. };
  40573.  
  40574.  
  40575. WebInspector.DebuggerDispatcher = function(debuggerModel)
  40576. {
  40577. this._debuggerModel = debuggerModel;
  40578. }
  40579.  
  40580. WebInspector.DebuggerDispatcher.prototype = {
  40581.  
  40582. paused: function(callFrames, reason, auxData)
  40583. {
  40584. this._debuggerModel._pausedScript(callFrames, reason, auxData);
  40585. },
  40586.  
  40587. resumed: function()
  40588. {
  40589. this._debuggerModel._resumedScript();
  40590. },
  40591.  
  40592. globalObjectCleared: function()
  40593. {
  40594. this._debuggerModel._globalObjectCleared();
  40595. },
  40596.  
  40597.  
  40598. scriptParsed: function(scriptId, sourceURL, startLine, startColumn, endLine, endColumn, isContentScript, sourceMapURL, hasSourceURL)
  40599. {
  40600. this._debuggerModel._parsedScriptSource(scriptId, sourceURL, startLine, startColumn, endLine, endColumn, !!isContentScript, sourceMapURL, hasSourceURL);
  40601. },
  40602.  
  40603.  
  40604. scriptFailedToParse: function(sourceURL, source, startingLine, errorLine, errorMessage)
  40605. {
  40606. },
  40607.  
  40608.  
  40609. breakpointResolved: function(breakpointId, location)
  40610. {
  40611. this._debuggerModel._breakpointResolved(breakpointId, location);
  40612. }
  40613. }
  40614.  
  40615.  
  40616. WebInspector.DebuggerModel.CallFrame = function(script, payload)
  40617. {
  40618. this._script = script;
  40619. this._payload = payload;
  40620. this._locations = [];
  40621. }
  40622.  
  40623. WebInspector.DebuggerModel.CallFrame.prototype = {
  40624.  
  40625. get script()
  40626. {
  40627. return this._script;
  40628. },
  40629.  
  40630.  
  40631. get type()
  40632. {
  40633. return this._payload.type;
  40634. },
  40635.  
  40636.  
  40637. get scopeChain()
  40638. {
  40639. return this._payload.scopeChain;
  40640. },
  40641.  
  40642.  
  40643. get this()
  40644. {
  40645. return this._payload.this;
  40646. },
  40647.  
  40648.  
  40649. get functionName()
  40650. {
  40651. return this._payload.functionName;
  40652. },
  40653.  
  40654.  
  40655. get location()
  40656. {
  40657. var rawLocation =   (this._payload.location);
  40658. return rawLocation;
  40659. },
  40660.  
  40661.  
  40662. evaluate: function(code, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, callback)
  40663. {
  40664.  
  40665. function didEvaluateOnCallFrame(error, result, wasThrown)
  40666. {
  40667. if (error) {
  40668. console.error(error);
  40669. callback(null, false);
  40670. return;
  40671. }
  40672. callback(result, wasThrown);
  40673. }
  40674. DebuggerAgent.evaluateOnCallFrame(this._payload.callFrameId, code, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, didEvaluateOnCallFrame.bind(this));
  40675. },
  40676.  
  40677.  
  40678. restart: function(callback)
  40679. {
  40680.  
  40681. function protocolCallback(error, callFrames, details)
  40682. {
  40683. if (!error)
  40684. WebInspector.debuggerModel.callStackModified(callFrames, details);
  40685. if (callback)
  40686. callback(error);
  40687. }
  40688. DebuggerAgent.restartFrame(this._payload.callFrameId, protocolCallback);
  40689. },
  40690.  
  40691.  
  40692. createLiveLocation: function(updateDelegate)
  40693. {
  40694. var location = this._script.createLiveLocation(this.location, updateDelegate);
  40695. this._locations.push(location);
  40696. return location;
  40697. },
  40698.  
  40699. dispose: function(updateDelegate)
  40700. {
  40701. for (var i = 0; i < this._locations.length; ++i)
  40702. this._locations[i].dispose();
  40703. this._locations = [];
  40704. }
  40705. }
  40706.  
  40707.  
  40708. WebInspector.DebuggerPausedDetails = function(model, callFrames, reason, auxData)
  40709. {
  40710. this.callFrames = [];
  40711. for (var i = 0; i < callFrames.length; ++i) {
  40712. var callFrame = callFrames[i];
  40713. var script = model.scriptForId(callFrame.location.scriptId);
  40714. if (script)
  40715. this.callFrames.push(new WebInspector.DebuggerModel.CallFrame(script, callFrame));
  40716. }
  40717. this.reason = reason;
  40718. this.auxData = auxData;
  40719. }
  40720.  
  40721. WebInspector.DebuggerPausedDetails.prototype = {
  40722. dispose: function()
  40723. {
  40724. for (var i = 0; i < this.callFrames.length; ++i) {
  40725. var callFrame = this.callFrames[i];
  40726. callFrame.dispose();
  40727. }
  40728. }
  40729. }
  40730.  
  40731.  
  40732. WebInspector.debuggerModel = null;
  40733.  
  40734.  
  40735.  
  40736.  
  40737.  
  40738.  
  40739. WebInspector.SourceMapping = function()
  40740. {
  40741. }
  40742.  
  40743. WebInspector.SourceMapping.prototype = {
  40744.  
  40745. rawLocationToUILocation: function(rawLocation) { },
  40746.  
  40747.  
  40748. uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber) { }
  40749. }
  40750.  
  40751.  
  40752. WebInspector.ScriptSourceMapping = function()
  40753. {
  40754. }
  40755.  
  40756. WebInspector.ScriptSourceMapping.prototype = {
  40757.  
  40758. addScript: function(script) { }
  40759. }
  40760.  
  40761.  
  40762.  
  40763.  
  40764.  
  40765. WebInspector.Script = function(scriptId, sourceURL, startLine, startColumn, endLine, endColumn, isContentScript, sourceMapURL, hasSourceURL)
  40766. {
  40767. this.scriptId = scriptId;
  40768. this.sourceURL = sourceURL;
  40769. this.lineOffset = startLine;
  40770. this.columnOffset = startColumn;
  40771. this.endLine = endLine;
  40772. this.endColumn = endColumn;
  40773. this.isContentScript = isContentScript;
  40774. this.sourceMapURL = sourceMapURL;
  40775. this.hasSourceURL = hasSourceURL;
  40776. this._locations = [];
  40777. }
  40778.  
  40779. WebInspector.Script.snippetSourceURLPrefix = "snippets:///";
  40780.  
  40781. WebInspector.Script.prototype = {
  40782.  
  40783. contentURL: function()
  40784. {
  40785. return this.sourceURL;
  40786. },
  40787.  
  40788.  
  40789. contentType: function()
  40790. {
  40791. return WebInspector.resourceTypes.Script;
  40792. },
  40793.  
  40794.  
  40795. requestContent: function(callback)
  40796. {
  40797. if (this._source) {
  40798. callback(this._source, false, "text/javascript");
  40799. return;
  40800. }
  40801.  
  40802.  
  40803. function didGetScriptSource(error, source)
  40804. {
  40805. this._source = error ? "" : source;
  40806. callback(this._source, false, "text/javascript");
  40807. }
  40808. if (this.scriptId) {
  40809.  
  40810. DebuggerAgent.getScriptSource(this.scriptId, didGetScriptSource.bind(this));
  40811. } else
  40812. callback("", false, "text/javascript");
  40813. },
  40814.  
  40815.  
  40816. searchInContent: function(query, caseSensitive, isRegex, callback)
  40817. {
  40818.  
  40819. function innerCallback(error, searchMatches)
  40820. {
  40821. if (error)
  40822. console.error(error);
  40823. var result = [];
  40824. for (var i = 0; i < searchMatches.length; ++i) {
  40825. var searchMatch = new WebInspector.ContentProvider.SearchMatch(searchMatches[i].lineNumber, searchMatches[i].lineContent);
  40826. result.push(searchMatch);
  40827. }
  40828. callback(result || []);
  40829. }
  40830.  
  40831. if (this.scriptId) {
  40832.  
  40833. DebuggerAgent.searchInContent(this.scriptId, query, caseSensitive, isRegex, innerCallback.bind(this));
  40834. } else
  40835. callback([]);
  40836. },
  40837.  
  40838.  
  40839. editSource: function(newSource, callback)
  40840. {
  40841.  
  40842. function didEditScriptSource(error, callFrames, debugData)
  40843. {
  40844.  
  40845. if (!error)
  40846. this._source = newSource;
  40847. callback(error, callFrames);
  40848. }
  40849. if (this.scriptId) {
  40850.  
  40851. DebuggerAgent.setScriptSource(this.scriptId, newSource, undefined, didEditScriptSource.bind(this));
  40852. } else
  40853. callback("Script failed to parse");
  40854. },
  40855.  
  40856.  
  40857. isInlineScript: function()
  40858. {
  40859. var startsAtZero = !this.lineOffset && !this.columnOffset;
  40860. return !!this.sourceURL && !startsAtZero;
  40861. },
  40862.  
  40863.  
  40864. isAnonymousScript: function()
  40865. {
  40866. return !this.sourceURL;
  40867. },
  40868.  
  40869.  
  40870. isSnippet: function()
  40871. {
  40872. return this.sourceURL && this.sourceURL.startsWith(WebInspector.Script.snippetSourceURLPrefix);
  40873. },
  40874.  
  40875.  
  40876. rawLocationToUILocation: function(lineNumber, columnNumber)
  40877. {
  40878. var uiLocation = this._sourceMapping.rawLocationToUILocation(new WebInspector.DebuggerModel.Location(this.scriptId, lineNumber, columnNumber || 0));
  40879. return uiLocation.uiSourceCode.overrideLocation(uiLocation);
  40880. },
  40881.  
  40882.  
  40883. setSourceMapping: function(sourceMapping)
  40884. {
  40885. this._sourceMapping = sourceMapping;
  40886. for (var i = 0; i < this._locations.length; ++i)
  40887. this._locations[i].update();
  40888. },
  40889.  
  40890.  
  40891. createLiveLocation: function(rawLocation, updateDelegate)
  40892. {
  40893. console.assert(rawLocation.scriptId === this.scriptId);
  40894. var location = new WebInspector.Script.Location(this, rawLocation, updateDelegate);
  40895. this._locations.push(location);
  40896. location.update();
  40897. return location;
  40898. }
  40899. }
  40900.  
  40901.  
  40902. WebInspector.Script.Location = function(script, rawLocation, updateDelegate)
  40903. {
  40904. WebInspector.LiveLocation.call(this, rawLocation, updateDelegate);
  40905. this._script = script;
  40906. }
  40907.  
  40908. WebInspector.Script.Location.prototype = {
  40909.  
  40910. uiLocation: function()
  40911. {
  40912. var debuggerModelLocation =   (this.rawLocation());
  40913. return this._script.rawLocationToUILocation(debuggerModelLocation.lineNumber, debuggerModelLocation.columnNumber);
  40914. },
  40915.  
  40916. dispose: function()
  40917. {
  40918. WebInspector.LiveLocation.prototype.dispose.call(this);
  40919. this._script._locations.remove(this);
  40920. },
  40921.  
  40922. __proto__: WebInspector.LiveLocation.prototype
  40923. }
  40924.  
  40925.  
  40926.  
  40927.  
  40928.  
  40929.  
  40930. WebInspector.LinkifierFormatter = function()
  40931. {
  40932. }
  40933.  
  40934. WebInspector.LinkifierFormatter.prototype = {
  40935.  
  40936. formatLiveAnchor: function(anchor, uiLocation) { }
  40937. }
  40938.  
  40939.  
  40940. WebInspector.Linkifier = function(formatter)
  40941. {
  40942. this._formatter = formatter || new WebInspector.Linkifier.DefaultFormatter(WebInspector.Linkifier.MaxLengthForDisplayedURLs);
  40943. this._liveLocations = [];
  40944. }
  40945.  
  40946. WebInspector.Linkifier.prototype = {
  40947.  
  40948. linkifyLocation: function(sourceURL, lineNumber, columnNumber, classes)
  40949. {
  40950. var rawLocation = WebInspector.debuggerModel.createRawLocationByURL(sourceURL, lineNumber, columnNumber || 0);
  40951. if (!rawLocation)
  40952. return WebInspector.linkifyResourceAsNode(sourceURL, lineNumber, classes);
  40953. return this.linkifyRawLocation(rawLocation, classes);
  40954. },
  40955.  
  40956.  
  40957. linkifyRawLocation: function(rawLocation, classes)
  40958. {
  40959. var script = WebInspector.debuggerModel.scriptForId(rawLocation.scriptId);
  40960. if (!script)
  40961. return null;
  40962. var anchor = WebInspector.linkifyURLAsNode("", "", classes, false);
  40963. var liveLocation = script.createLiveLocation(rawLocation, this._updateAnchor.bind(this, anchor));
  40964. this._liveLocations.push(liveLocation);
  40965. return anchor;
  40966. },
  40967.  
  40968.  
  40969. linkifyCSSRuleLocation: function(rule)
  40970. {
  40971. var anchor = WebInspector.linkifyURLAsNode("", "", "", false);
  40972. var liveLocation = WebInspector.cssModel.createLiveLocation(rule, this._updateAnchor.bind(this, anchor));
  40973. if (!liveLocation)
  40974. return null;
  40975. this._liveLocations.push(liveLocation);
  40976. return anchor;
  40977. },
  40978.  
  40979. reset: function()
  40980. {
  40981. for (var i = 0; i < this._liveLocations.length; ++i)
  40982. this._liveLocations[i].dispose();
  40983. this._liveLocations = [];
  40984. },
  40985.  
  40986.  
  40987. _updateAnchor: function(anchor, uiLocation)
  40988. {
  40989. anchor.preferredPanel = "scripts";
  40990. anchor.href = sanitizeHref(uiLocation.uiSourceCode.url);
  40991. anchor.uiSourceCode = uiLocation.uiSourceCode;
  40992. anchor.lineNumber = uiLocation.lineNumber;
  40993. this._formatter.formatLiveAnchor(anchor, uiLocation);
  40994. }
  40995. }
  40996.  
  40997.  
  40998. WebInspector.Linkifier.DefaultFormatter = function(maxLength)
  40999. {
  41000. this._maxLength = maxLength;
  41001. }
  41002.  
  41003. WebInspector.Linkifier.DefaultFormatter.prototype = {
  41004.  
  41005. formatLiveAnchor: function(anchor, uiLocation)
  41006. {
  41007. var text = WebInspector.formatLinkText(uiLocation.uiSourceCode.url, uiLocation.lineNumber);
  41008. if (this._maxLength)
  41009. text = text.trimMiddle(this._maxLength);
  41010. anchor.textContent = text;
  41011.  
  41012. var titleText = uiLocation.uiSourceCode.url;
  41013. if (typeof uiLocation.lineNumber === "number")
  41014. titleText += ":" + (uiLocation.lineNumber + 1);
  41015. anchor.title = titleText;
  41016. },
  41017.  
  41018. __proto__: WebInspector.LinkifierFormatter.prototype
  41019. }
  41020.  
  41021.  
  41022. WebInspector.Linkifier.DefaultCSSFormatter = function()
  41023. {
  41024. WebInspector.Linkifier.DefaultFormatter.call(this);
  41025. }
  41026.  
  41027. WebInspector.Linkifier.DefaultCSSFormatter.prototype = {
  41028.  
  41029. formatLiveAnchor: function(anchor, uiLocation)
  41030. {
  41031. WebInspector.Linkifier.DefaultFormatter.prototype.formatLiveAnchor.call(this, anchor, uiLocation);
  41032. anchor.classList.add("webkit-html-resource-link");
  41033. anchor.setAttribute("data-uncopyable", anchor.textContent);
  41034. anchor.textContent = "";
  41035. },
  41036. __proto__: WebInspector.Linkifier.DefaultFormatter.prototype
  41037. }
  41038.  
  41039.  
  41040. WebInspector.Linkifier.MaxLengthForDisplayedURLs = 150;
  41041.  
  41042.  
  41043.  
  41044.  
  41045.  
  41046.  
  41047. WebInspector.DebuggerScriptMapping = function(workspace, networkWorkspaceProvider)
  41048. {
  41049. this._resourceMapping = new WebInspector.ResourceScriptMapping(workspace);
  41050. this._compilerMapping = new WebInspector.CompilerScriptMapping(workspace, networkWorkspaceProvider);
  41051. this._snippetMapping = WebInspector.scriptSnippetModel.scriptMapping;
  41052.  
  41053. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this);
  41054. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.FailedToParseScriptSource, this._parsedScriptSource, this);
  41055. }
  41056.  
  41057. WebInspector.DebuggerScriptMapping.prototype = {
  41058.  
  41059. _parsedScriptSource: function(event)
  41060. {
  41061. var script =   (event.data);
  41062. var mapping = this._mappingForScript(script);
  41063. mapping.addScript(script);
  41064. },
  41065.  
  41066.  
  41067. _mappingForScript: function(script)
  41068. {
  41069. if (WebInspector.experimentsSettings.snippetsSupport.isEnabled() && script.isSnippet())
  41070. return this._snippetMapping;
  41071.  
  41072. if (WebInspector.settings.sourceMapsEnabled.get() && script.sourceMapURL) {
  41073. if (this._compilerMapping.loadSourceMapForScript(script))
  41074. return this._compilerMapping;
  41075. }
  41076.  
  41077. return this._resourceMapping;
  41078. }
  41079. }
  41080.  
  41081.  
  41082.  
  41083.  
  41084.  
  41085.  
  41086. WebInspector.PresentationConsoleMessageHelper = function(uiSourceCodeProvider)
  41087. {
  41088.  
  41089. this._pendingConsoleMessages = {};
  41090. this._presentationConsoleMessages = [];
  41091. this._uiSourceCodeProvider = uiSourceCodeProvider;
  41092.  
  41093. WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, this._consoleMessageAdded, this);
  41094. WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.RepeatCountUpdated, this._consoleMessageAdded, this);
  41095. WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.ConsoleCleared, this._consoleCleared, this);
  41096.  
  41097. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this);
  41098. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.FailedToParseScriptSource, this._parsedScriptSource, this);
  41099. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjectCleared, this._debuggerReset, this);
  41100. }
  41101.  
  41102. WebInspector.PresentationConsoleMessageHelper.prototype = {
  41103.  
  41104. _consoleMessageAdded: function(event)
  41105. {
  41106. var message =   (event.data);
  41107. if (!message.url || !message.isErrorOrWarning())
  41108. return;
  41109.  
  41110. var rawLocation = message.location();
  41111. if (rawLocation)
  41112. this._addConsoleMessageToScript(message, rawLocation);
  41113. else
  41114. this._addPendingConsoleMessage(message);
  41115. },
  41116.  
  41117.  
  41118. _addConsoleMessageToScript: function(message, rawLocation)
  41119. {
  41120. this._presentationConsoleMessages.push(new WebInspector.PresentationConsoleMessage(message, rawLocation));
  41121. },
  41122.  
  41123.  
  41124. _addPendingConsoleMessage: function(message)
  41125. {
  41126. if (!message.url)
  41127. return;
  41128. if (!this._pendingConsoleMessages[message.url])
  41129. this._pendingConsoleMessages[message.url] = [];
  41130. this._pendingConsoleMessages[message.url].push(message);
  41131. },
  41132.  
  41133.  
  41134. _parsedScriptSource: function(event)
  41135. {
  41136. var script =   (event.data);
  41137.  
  41138. var messages = this._pendingConsoleMessages[script.sourceURL];
  41139. if (!messages)
  41140. return;
  41141.  
  41142. var pendingMessages = [];
  41143. for (var i = 0; i < messages.length; i++) {
  41144. var message = messages[i];
  41145. var rawLocation =   (message.location());
  41146. if (script.scriptId === rawLocation.scriptId)
  41147. this._addConsoleMessageToScript(message, rawLocation);
  41148. else
  41149. pendingMessages.push(message);
  41150. }
  41151.  
  41152. if (pendingMessages.length)
  41153. this._pendingConsoleMessages[script.sourceURL] = pendingMessages;
  41154. else
  41155. delete this._pendingConsoleMessages[script.sourceURL];
  41156. },
  41157.  
  41158. _consoleCleared: function()
  41159. {
  41160. this._pendingConsoleMessages = {};
  41161. for (var i = 0; i < this._presentationConsoleMessages.length; ++i)
  41162. this._presentationConsoleMessages[i].dispose();
  41163. this._presentationConsoleMessages = [];
  41164. var uiSourceCodes = this._uiSourceCodeProvider.uiSourceCodes();
  41165. for (var i = 0; i < uiSourceCodes.length; ++i)
  41166. uiSourceCodes[i].consoleMessagesCleared();
  41167. },
  41168.  
  41169. _debuggerReset: function()
  41170. {
  41171. this._pendingConsoleMessages = {};
  41172. this._presentationConsoleMessages = [];
  41173. }
  41174. }
  41175.  
  41176.  
  41177. WebInspector.PresentationConsoleMessage = function(message, rawLocation)
  41178. {
  41179. this.originalMessage = message;
  41180. this._liveLocation = WebInspector.debuggerModel.createLiveLocation(rawLocation, this._updateLocation.bind(this));
  41181. }
  41182.  
  41183. WebInspector.PresentationConsoleMessage.prototype = {
  41184.  
  41185. _updateLocation: function(uiLocation)
  41186. {
  41187. if (this._uiLocation)
  41188. this._uiLocation.uiSourceCode.consoleMessageRemoved(this);
  41189. this._uiLocation = uiLocation;
  41190. this._uiLocation.uiSourceCode.consoleMessageAdded(this);
  41191. },
  41192.  
  41193. get lineNumber()
  41194. {
  41195. return this._uiLocation.lineNumber;
  41196. },
  41197.  
  41198. dispose: function()
  41199. {
  41200. this._liveLocation.dispose();
  41201. }
  41202. }
  41203.  
  41204.  
  41205.  
  41206.  
  41207.  
  41208.  
  41209. WebInspector.NetworkWorkspaceProvider = function()
  41210. {
  41211.  
  41212. this._contentProviders = {};
  41213. }
  41214.  
  41215. WebInspector.NetworkWorkspaceProvider.prototype = {
  41216.  
  41217. requestFileContent: function(path, callback)
  41218. {
  41219. var contentProvider = this._contentProviders[path];
  41220. contentProvider.requestContent(callback);
  41221. },
  41222.  
  41223.  
  41224. setFileContent: function(path, newContent, callback)
  41225. {
  41226. callback(null);
  41227. },
  41228.  
  41229.  
  41230. searchInFileContent: function(path, query, caseSensitive, isRegex, callback)
  41231. {
  41232. var contentProvider = this._contentProviders[path];
  41233. contentProvider.searchInContent(query, caseSensitive, isRegex, callback);
  41234. },
  41235.  
  41236.  
  41237. addFile: function(path, contentProvider, isEditable, isContentScript, isSnippet)
  41238. {
  41239. var fileDescriptor = new WebInspector.FileDescriptor(path, contentProvider.contentType(), isEditable, isContentScript, isSnippet);
  41240. this._contentProviders[path] = contentProvider;
  41241. this.dispatchEventToListeners(WebInspector.WorkspaceProvider.Events.FileAdded, fileDescriptor);
  41242. },
  41243.  
  41244.  
  41245. removeFile: function(path)
  41246. {
  41247. delete this._contentProviders[path];
  41248. this.dispatchEventToListeners(WebInspector.WorkspaceProvider.Events.FileRemoved, path);
  41249. },
  41250.  
  41251. reset: function()
  41252. {
  41253. this._contentProviders = {};
  41254. },
  41255.  
  41256. __proto__: WebInspector.Object.prototype
  41257. }
  41258.  
  41259.  
  41260. WebInspector.networkWorkspaceProvider = null;
  41261.  
  41262.  
  41263.  
  41264.  
  41265.  
  41266.  
  41267. WebInspector.WorkspaceController = function(workspace)
  41268. {
  41269. this._workspace = workspace;
  41270. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, this._mainFrameNavigated, this);
  41271. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameAdded, this._frameAdded, this);
  41272. }
  41273.  
  41274. WebInspector.WorkspaceController.prototype = {
  41275. _mainFrameNavigated: function()
  41276. {
  41277. WebInspector.Revision.filterOutStaleRevisions();
  41278. this._workspace.dispatchEventToListeners(WebInspector.Workspace.Events.ProjectWillReset, this._workspace.project());
  41279. this._workspace.project().reset();
  41280. this._workspace.reset();
  41281. this._workspace.dispatchEventToListeners(WebInspector.Workspace.Events.ProjectDidReset, this._workspace.project());
  41282. },
  41283.  
  41284. _frameAdded: function(event)
  41285. {
  41286. var frame =   (event.data);
  41287. if (frame.isMainFrame())
  41288. WebInspector.Revision.filterOutStaleRevisions();
  41289. }
  41290. }
  41291.  
  41292.  
  41293. WebInspector.FileDescriptor = function(path, contentType, isEditable, isContentScript, isSnippet)
  41294. {
  41295. this.path = path;
  41296. this.contentType = contentType;
  41297. this.isEditable = isEditable;
  41298. this.isContentScript = isContentScript || false;
  41299. this.isSnippet = isSnippet || false;
  41300. }
  41301.  
  41302.  
  41303. WebInspector.WorkspaceProvider = function() { }
  41304.  
  41305. WebInspector.WorkspaceProvider.Events = {
  41306. FileAdded: "FileAdded",
  41307. FileRemoved: "FileRemoved"
  41308. }
  41309.  
  41310. WebInspector.WorkspaceProvider.prototype = {
  41311.  
  41312. requestFileContent: function(path, callback) { },
  41313.  
  41314.  
  41315. searchInFileContent: function(path, query, caseSensitive, isRegex, callback) { },
  41316.  
  41317.  
  41318. addEventListener: function(eventType, listener, thisObject) { },
  41319.  
  41320.  
  41321. removeEventListener: function(eventType, listener, thisObject) { }
  41322. }
  41323.  
  41324.  
  41325. WebInspector.workspaceController = null;
  41326.  
  41327.  
  41328. WebInspector.Project = function(workspace, workspaceProvider)
  41329. {
  41330. this._uiSourceCodes = [];
  41331. this._workspace = workspace;
  41332. this._workspaceProvider = workspaceProvider;
  41333. this._workspaceProvider.addEventListener(WebInspector.WorkspaceProvider.Events.FileAdded, this._fileAdded, this);
  41334. this._workspaceProvider.addEventListener(WebInspector.WorkspaceProvider.Events.FileRemoved, this._fileRemoved, this);
  41335. }
  41336.  
  41337. WebInspector.Project.prototype = {
  41338. reset: function()
  41339. {
  41340. this._workspaceProvider.reset();
  41341. this._uiSourceCodes = [];
  41342. },
  41343.  
  41344. _fileAdded: function(event)
  41345. {
  41346. var fileDescriptor =   (event.data);
  41347. var uiSourceCode = this.uiSourceCodeForURL(fileDescriptor.path);
  41348. if (uiSourceCode) {
  41349.  
  41350. return;
  41351. }
  41352. uiSourceCode = new WebInspector.UISourceCode(this._workspace, fileDescriptor.path, fileDescriptor.contentType, fileDescriptor.isEditable);
  41353. uiSourceCode.isContentScript = fileDescriptor.isContentScript;
  41354. uiSourceCode.isSnippet = fileDescriptor.isSnippet;
  41355. this._uiSourceCodes.push(uiSourceCode);
  41356. this._workspace.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, uiSourceCode);
  41357. },
  41358.  
  41359. _fileRemoved: function(event)
  41360. {
  41361. var path =   (event.data);
  41362. var uiSourceCode = this.uiSourceCodeForURL(path);
  41363. if (!uiSourceCode)
  41364. return;
  41365. this._uiSourceCodes.splice(this._uiSourceCodes.indexOf(uiSourceCode), 1);
  41366. this._workspace.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.UISourceCodeRemoved, uiSourceCode);
  41367. },
  41368.  
  41369.  
  41370. uiSourceCodeForURL: function(url)
  41371. {
  41372. for (var i = 0; i < this._uiSourceCodes.length; ++i) {
  41373. if (this._uiSourceCodes[i].url === url)
  41374. return this._uiSourceCodes[i];
  41375. }
  41376. return null;
  41377. },
  41378.  
  41379.  
  41380. uiSourceCodes: function()
  41381. {
  41382. return this._uiSourceCodes;
  41383. },
  41384.  
  41385.  
  41386. requestFileContent: function(path, callback)
  41387. {
  41388. this._workspaceProvider.requestFileContent(path, callback);
  41389. },
  41390.  
  41391.  
  41392. searchInFileContent: function(path, query, caseSensitive, isRegex, callback)
  41393. {
  41394. this._workspaceProvider.searchInFileContent(path, query, caseSensitive, isRegex, callback);
  41395. }
  41396. }
  41397.  
  41398.  
  41399. WebInspector.Workspace = function()
  41400. {
  41401.  
  41402. this._temporaryContentProviders = new Map();
  41403. }
  41404.  
  41405. WebInspector.Workspace.Events = {
  41406. UISourceCodeContentCommitted: "UISourceCodeContentCommitted",
  41407. ProjectWillReset: "ProjectWillReset",
  41408. ProjectDidReset: "ProjectDidReset"
  41409. }
  41410.  
  41411. WebInspector.Workspace.prototype = {
  41412.  
  41413. uiSourceCodeForURL: function(url)
  41414. {
  41415. return this._project.uiSourceCodeForURL(url);
  41416. },
  41417.  
  41418.  
  41419. addProject: function(projectName, workspaceProvider)
  41420. {
  41421.  
  41422. this._project = new WebInspector.Project(this, workspaceProvider);
  41423. },
  41424.  
  41425.  
  41426. project: function()
  41427. {
  41428. return this._project;
  41429. },
  41430.  
  41431.  
  41432. uiSourceCodes: function()
  41433. {
  41434. return this._project.uiSourceCodes();
  41435. },
  41436.  
  41437.  
  41438. addTemporaryUISourceCode: function(path, contentProvider, isEditable, isContentScript, isSnippet)
  41439. {
  41440. var uiSourceCode = new WebInspector.UISourceCode(this, path, contentProvider.contentType(), isEditable);
  41441. this._temporaryContentProviders.put(uiSourceCode, contentProvider);
  41442. uiSourceCode.isContentScript = isContentScript;
  41443. uiSourceCode.isSnippet = isSnippet;
  41444. uiSourceCode.isTemporary = true;
  41445. this.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.TemporaryUISourceCodeAdded, uiSourceCode);
  41446. return uiSourceCode;
  41447. },
  41448.  
  41449.  
  41450. removeTemporaryUISourceCode: function(uiSourceCode)
  41451. {
  41452. this._temporaryContentProviders.remove(uiSourceCode.url);
  41453. this.dispatchEventToListeners(WebInspector.UISourceCodeProvider.Events.TemporaryUISourceCodeRemoved, uiSourceCode);
  41454. },
  41455.  
  41456.  
  41457. requestFileContent: function(uiSourceCode, callback)
  41458. {
  41459. if (this._temporaryContentProviders.get(uiSourceCode)) {
  41460. this._temporaryContentProviders.get(uiSourceCode).requestContent(callback);
  41461. return;
  41462. }
  41463. this._project.requestFileContent(uiSourceCode.url, callback);
  41464. },
  41465.  
  41466.  
  41467. searchInFileContent: function(uiSourceCode, query, caseSensitive, isRegex, callback)
  41468. {
  41469. if (this._temporaryContentProviders.get(uiSourceCode)) {
  41470. this._temporaryContentProviders.get(uiSourceCode).searchInContent(query, caseSensitive, isRegex, callback);
  41471. return;
  41472. }
  41473. this._project.searchInFileContent(uiSourceCode.url, query, caseSensitive, isRegex, callback);
  41474. },
  41475.  
  41476. reset: function()
  41477. {
  41478. this._temporaryContentProviders = new Map();
  41479. },
  41480.  
  41481. __proto__: WebInspector.Object.prototype
  41482. }
  41483.  
  41484.  
  41485. WebInspector.workspace = null;
  41486.  
  41487.  
  41488.  
  41489.  
  41490.  
  41491.  
  41492. WebInspector.BreakpointManager = function(breakpointStorage, debuggerModel, workspace)
  41493. {
  41494. this._storage = new WebInspector.BreakpointManager.Storage(this, breakpointStorage);
  41495. this._debuggerModel = debuggerModel;
  41496. this._workspace = workspace;
  41497.  
  41498. this._breakpoints = [];
  41499. this._breakpointForDebuggerId = {};
  41500. this._breakpointsForUISourceCode = new Map();
  41501. this._sourceFilesWithRestoredBreakpoints = {};
  41502.  
  41503. this._debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.BreakpointResolved, this._breakpointResolved, this);
  41504. this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._workspaceReset, this);
  41505. this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, this._uiSourceCodeAdded, this);
  41506. this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.TemporaryUISourceCodeAdded, this._uiSourceCodeAdded, this);
  41507. this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.TemporaryUISourceCodeRemoved, this._uiSourceCodeRemoved, this);
  41508. }
  41509.  
  41510. WebInspector.BreakpointManager.Events = {
  41511. BreakpointAdded: "breakpoint-added",
  41512. BreakpointRemoved: "breakpoint-removed"
  41513. }
  41514.  
  41515. WebInspector.BreakpointManager.sourceFileId = function(uiSourceCode)
  41516. {
  41517. return uiSourceCode.formatted() ? "deobfuscated:" + uiSourceCode.url : uiSourceCode.url;
  41518. }
  41519.  
  41520. WebInspector.BreakpointManager.prototype = {
  41521.  
  41522. _restoreBreakpoints: function(uiSourceCode)
  41523. {
  41524. var sourceFileId = WebInspector.BreakpointManager.sourceFileId(uiSourceCode);
  41525. if (!sourceFileId || this._sourceFilesWithRestoredBreakpoints[sourceFileId])
  41526. return;
  41527. this._sourceFilesWithRestoredBreakpoints[sourceFileId] = true;
  41528.  
  41529.  
  41530. for (var debuggerId in this._breakpointForDebuggerId) {
  41531. var breakpoint = this._breakpointForDebuggerId[debuggerId];
  41532. if (breakpoint._sourceFileId !== sourceFileId)
  41533. continue;
  41534. this._debuggerModel.removeBreakpoint(debuggerId);
  41535. delete this._breakpointForDebuggerId[debuggerId];
  41536. delete breakpoint._debuggerId;
  41537. }
  41538. this._storage._restoreBreakpoints(uiSourceCode);
  41539. },
  41540.  
  41541.  
  41542. _uiSourceCodeAdded: function(event)
  41543. {
  41544. var uiSourceCode =   (event.data);
  41545. if (uiSourceCode.contentType() === WebInspector.resourceTypes.Script || uiSourceCode.contentType() === WebInspector.resourceTypes.Document) {
  41546. this._restoreBreakpoints(uiSourceCode);
  41547. uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.FormattedChanged, this._uiSourceCodeFormatted, this);
  41548. }
  41549. },
  41550.  
  41551.  
  41552. _uiSourceCodeFormatted: function(event)
  41553. {
  41554. var uiSourceCode =   (event.target);
  41555. this._restoreBreakpoints(uiSourceCode);
  41556. },
  41557.  
  41558.  
  41559. _uiSourceCodeRemoved: function(event)
  41560. {
  41561. var uiSourceCode =   (event.data);
  41562. if (uiSourceCode.contentType() !== WebInspector.resourceTypes.Script && uiSourceCode.contentType() !== WebInspector.resourceTypes.Document)
  41563. return;
  41564. if (uiSourceCode.divergedVersion)
  41565. return;
  41566.  
  41567. var sourceFileId = WebInspector.BreakpointManager.sourceFileId(uiSourceCode);
  41568. if (!sourceFileId)
  41569. return;
  41570.  
  41571. var breakpoints = this._breakpoints.slice();
  41572. for (var i = 0; i < breakpoints.length; ++i) {
  41573. var breakpoint = breakpoints[i];
  41574. for (var stringifiedLocation in breakpoint._uiLocations) {
  41575. var uiLocation = breakpoint._uiLocations[stringifiedLocation];
  41576. if (uiLocation.uiSourceCode === uiSourceCode)
  41577. breakpoint.remove(true);
  41578. }
  41579. }
  41580.  
  41581. delete this._sourceFilesWithRestoredBreakpoints[sourceFileId];
  41582.  
  41583. var uiSourceCodes = this._workspace.uiSourceCodes();
  41584. for (var i = 0; i < uiSourceCodes.length; ++i)
  41585. this._restoreBreakpoints(uiSourceCodes[i]);
  41586. },
  41587.  
  41588.  
  41589. setBreakpoint: function(uiSourceCode, lineNumber, condition, enabled)
  41590. {
  41591. this._debuggerModel.setBreakpointsActive(true);
  41592. return this._innerSetBreakpoint(uiSourceCode, lineNumber, condition, enabled);
  41593. },
  41594.  
  41595.  
  41596. _innerSetBreakpoint: function(uiSourceCode, lineNumber, condition, enabled)
  41597. {
  41598. var breakpoint = this.findBreakpoint(uiSourceCode, lineNumber);
  41599. if (breakpoint) {
  41600. breakpoint._updateBreakpoint(condition, enabled);
  41601. return breakpoint;
  41602. }
  41603. breakpoint = new WebInspector.BreakpointManager.Breakpoint(this, uiSourceCode, lineNumber, condition, enabled);
  41604. this._breakpoints.push(breakpoint);
  41605. return breakpoint;
  41606. },
  41607.  
  41608.  
  41609. findBreakpoint: function(uiSourceCode, lineNumber)
  41610. {
  41611. var breakpoints = this._breakpointsForUISourceCode.get(uiSourceCode);
  41612. var lineBreakpoints = breakpoints ? breakpoints[lineNumber] : null;
  41613. return lineBreakpoints ? lineBreakpoints[0] : null;
  41614. },
  41615.  
  41616.  
  41617. _filteredBreakpointLocations: function(filter)
  41618. {
  41619. var result = [];
  41620. for (var i = 0; i < this._breakpoints.length; ++i) {
  41621. var breakpoint = this._breakpoints[i];
  41622. for (var stringifiedLocation in breakpoint._uiLocations) {
  41623. var uiLocation = breakpoint._uiLocations[stringifiedLocation];
  41624. if (filter(breakpoint, uiLocation))
  41625. result.push({breakpoint: breakpoint, uiLocation: uiLocation});
  41626. }
  41627. }
  41628. return result;
  41629. },
  41630.  
  41631.  
  41632. breakpointLocationsForUISourceCode: function(uiSourceCode)
  41633. {
  41634. function filter(breakpoint, uiLocation)
  41635. {
  41636. return uiLocation.uiSourceCode === uiSourceCode;
  41637. }
  41638.  
  41639. return this._filteredBreakpointLocations(filter);
  41640. },
  41641.  
  41642.  
  41643. allBreakpointLocations: function()
  41644. {
  41645. return this._filteredBreakpointLocations(function(breakpoint, uiLocation) { return true; });
  41646. },
  41647.  
  41648.  
  41649. toggleAllBreakpoints: function(toggleState)
  41650. {
  41651. for (var i = 0; i < this._breakpoints.length; ++i) {
  41652. var breakpoint = this._breakpoints[i];
  41653. if (breakpoint.enabled() != toggleState)
  41654. breakpoint.setEnabled(toggleState);
  41655. }
  41656. },
  41657.  
  41658. removeAllBreakpoints: function()
  41659. {
  41660. var breakpoints = this._breakpoints.slice();
  41661. for (var i = 0; i < breakpoints.length; ++i)
  41662. breakpoints[i].remove();
  41663. },
  41664.  
  41665. reset: function()
  41666. {
  41667.  
  41668. this._storage._muted = true;
  41669. this.removeAllBreakpoints();
  41670. delete this._storage._muted;
  41671.  
  41672.  
  41673. for (var debuggerId in this._breakpointForDebuggerId)
  41674. this._debuggerModel.removeBreakpoint(debuggerId);
  41675. this._breakpointForDebuggerId = {};
  41676. this._sourceFilesWithRestoredBreakpoints = {};
  41677. },
  41678.  
  41679. _workspaceReset: function()
  41680. {
  41681. var breakpoints = this._breakpoints.slice();
  41682. for (var i = 0; i < breakpoints.length; ++i) {
  41683. breakpoints[i]._resetLocations();
  41684. breakpoints[i]._isProvisional = true;
  41685. }
  41686. this._breakpoints = [];
  41687. this._breakpointsForUISourceCode.clear();
  41688. this._sourceFilesWithRestoredBreakpoints = {};
  41689. },
  41690.  
  41691. _breakpointResolved: function(event)
  41692. {
  41693. var breakpointId =   (event.data.breakpointId);
  41694. var location =   (event.data.location);
  41695. var breakpoint = this._breakpointForDebuggerId[breakpointId];
  41696. if (!breakpoint || breakpoint._isProvisional)
  41697. return;
  41698. breakpoint._addResolvedLocation(location);
  41699. },
  41700.  
  41701.  
  41702. _removeBreakpoint: function(breakpoint, removeFromStorage)
  41703. {
  41704. console.assert(!breakpoint._debuggerId)
  41705. this._breakpoints.remove(breakpoint);
  41706. if (removeFromStorage)
  41707. this._storage._removeBreakpoint(breakpoint);
  41708. },
  41709.  
  41710.  
  41711. _uiLocationAdded: function(breakpoint, uiLocation)
  41712. {
  41713. var breakpoints = this._breakpointsForUISourceCode.get(uiLocation.uiSourceCode);
  41714. if (!breakpoints) {
  41715. breakpoints = {};
  41716. this._breakpointsForUISourceCode.put(uiLocation.uiSourceCode, breakpoints);
  41717. }
  41718.  
  41719. var lineBreakpoints = breakpoints[uiLocation.lineNumber];
  41720. if (!lineBreakpoints) {
  41721. lineBreakpoints = [];
  41722. breakpoints[uiLocation.lineNumber] = lineBreakpoints;
  41723. }
  41724.  
  41725. lineBreakpoints.push(breakpoint);
  41726. this.dispatchEventToListeners(WebInspector.BreakpointManager.Events.BreakpointAdded, {breakpoint: breakpoint, uiLocation: uiLocation});
  41727. },
  41728.  
  41729.  
  41730. _uiLocationRemoved: function(breakpoint, uiLocation)
  41731. {
  41732. var breakpoints = this._breakpointsForUISourceCode.get(uiLocation.uiSourceCode);
  41733. if (!breakpoints)
  41734. return;
  41735.  
  41736. var lineBreakpoints = breakpoints[uiLocation.lineNumber];
  41737. if (!lineBreakpoints)
  41738. return;
  41739.  
  41740. lineBreakpoints.remove(breakpoint);
  41741. if (!lineBreakpoints.length)
  41742. delete breakpoints[uiLocation.lineNumber];
  41743. this.dispatchEventToListeners(WebInspector.BreakpointManager.Events.BreakpointRemoved, {breakpoint: breakpoint, uiLocation: uiLocation});
  41744. },
  41745.  
  41746. __proto__: WebInspector.Object.prototype
  41747. }
  41748.  
  41749.  
  41750. WebInspector.BreakpointManager.Breakpoint = function(breakpointManager, uiSourceCode, lineNumber, condition, enabled)
  41751. {
  41752. this._breakpointManager = breakpointManager;
  41753. this._primaryUILocation = new WebInspector.UILocation(uiSourceCode, lineNumber, 0);
  41754. this._sourceFileId = WebInspector.BreakpointManager.sourceFileId(uiSourceCode);
  41755.  
  41756. this._liveLocations = [];
  41757.  
  41758. this._uiLocations = {};
  41759.  
  41760.  
  41761. this._condition;
  41762. this._enabled;
  41763. this._updateBreakpoint(condition, enabled);
  41764. }
  41765.  
  41766. WebInspector.BreakpointManager.Breakpoint.prototype = {
  41767.  
  41768. primaryUILocation: function()
  41769. {
  41770. return this._primaryUILocation;
  41771. },
  41772.  
  41773.  
  41774. _addResolvedLocation: function(location)
  41775. {
  41776. this._liveLocations.push(this._breakpointManager._debuggerModel.createLiveLocation(location, this._locationUpdated.bind(this, location)));
  41777. },
  41778.  
  41779.  
  41780. _locationUpdated: function(location, uiLocation)
  41781. {
  41782. var stringifiedLocation = location.scriptId + ":" + location.lineNumber + ":" + location.columnNumber;
  41783. var oldUILocation =   (this._uiLocations[stringifiedLocation]);
  41784. if (oldUILocation)
  41785. this._breakpointManager._uiLocationRemoved(this, oldUILocation);
  41786. if (this._uiLocations[""]) {
  41787. delete this._uiLocations[""];
  41788. this._breakpointManager._uiLocationRemoved(this, this._primaryUILocation);
  41789. }
  41790. this._uiLocations[stringifiedLocation] = uiLocation;
  41791. this._breakpointManager._uiLocationAdded(this, uiLocation);
  41792. },
  41793.  
  41794.  
  41795. enabled: function()
  41796. {
  41797. return this._enabled;
  41798. },
  41799.  
  41800.  
  41801. setEnabled: function(enabled)
  41802. {
  41803. this._updateBreakpoint(this._condition, enabled);
  41804. },
  41805.  
  41806.  
  41807. condition: function()
  41808. {
  41809. return this._condition;
  41810. },
  41811.  
  41812.  
  41813. setCondition: function(condition)
  41814. {
  41815. this._updateBreakpoint(condition, this._enabled);
  41816. },
  41817.  
  41818.  
  41819. _updateBreakpoint: function(condition, enabled)
  41820. {
  41821. if (this._enabled === enabled && this._condition === condition)
  41822. return;
  41823.  
  41824. if (this._enabled)
  41825. this._removeFromDebugger();
  41826.  
  41827. this._enabled = enabled;
  41828. this._condition = condition;
  41829. this._breakpointManager._storage._updateBreakpoint(this);
  41830.  
  41831. var scriptFile = this._primaryUILocation.uiSourceCode.scriptFile();
  41832. if (this._enabled && !(scriptFile && scriptFile.hasDivergedFromVM())) {
  41833. this._setInDebugger();
  41834. return;
  41835. }
  41836.  
  41837. this._fakeBreakpointAtPrimaryLocation();
  41838. },
  41839.  
  41840.  
  41841. remove: function(keepInStorage)
  41842. {
  41843. var removeFromStorage = !keepInStorage;
  41844. this._resetLocations();
  41845. this._removeFromDebugger();
  41846. this._breakpointManager._removeBreakpoint(this, removeFromStorage);
  41847. },
  41848.  
  41849. _setInDebugger: function()
  41850. {
  41851. var rawLocation = this._primaryUILocation.uiLocationToRawLocation();
  41852. var debuggerModelLocation =   (rawLocation);
  41853. if (debuggerModelLocation)
  41854. this._breakpointManager._debuggerModel.setBreakpointByScriptLocation(debuggerModelLocation, this._condition, didSetBreakpoint.bind(this));
  41855. else
  41856. this._breakpointManager._debuggerModel.setBreakpointByURL(this._primaryUILocation.uiSourceCode.url, this._primaryUILocation.lineNumber, 0, this._condition, didSetBreakpoint.bind(this));
  41857.  
  41858.  
  41859. function didSetBreakpoint(breakpointId, locations)
  41860. {
  41861. if (!breakpointId) {
  41862. this._resetLocations();
  41863. this._breakpointManager._removeBreakpoint(this, false);
  41864. return;
  41865. }
  41866.  
  41867. this._debuggerId = breakpointId;
  41868. this._breakpointManager._breakpointForDebuggerId[breakpointId] = this;
  41869.  
  41870. if (!locations.length) {
  41871. this._fakeBreakpointAtPrimaryLocation();
  41872. return;
  41873. }
  41874.  
  41875. this._resetLocations();
  41876. for (var i = 0; i < locations.length; ++i) {
  41877. var script = this._breakpointManager._debuggerModel.scriptForId(locations[i].scriptId);
  41878. var uiLocation = script.rawLocationToUILocation(locations[i].lineNumber, locations[i].columnNumber);
  41879. if (this._breakpointManager.findBreakpoint(uiLocation.uiSourceCode, uiLocation.lineNumber)) {
  41880.  
  41881. this.remove();
  41882. return;
  41883. }
  41884. }
  41885.  
  41886. for (var i = 0; i < locations.length; ++i)
  41887. this._addResolvedLocation(locations[i]);
  41888. }
  41889. },
  41890.  
  41891. _removeFromDebugger: function()
  41892. {
  41893. if (this._debuggerId) {
  41894. this._breakpointManager._debuggerModel.removeBreakpoint(this._debuggerId);
  41895. delete this._breakpointManager._breakpointForDebuggerId[this._debuggerId];
  41896. delete this._debuggerId;
  41897. }
  41898. },
  41899.  
  41900. _resetLocations: function()
  41901. {
  41902. for (var stringifiedLocation in this._uiLocations)
  41903. this._breakpointManager._uiLocationRemoved(this, this._uiLocations[stringifiedLocation]);
  41904.  
  41905. for (var i = 0; i < this._liveLocations.length; ++i)
  41906. this._liveLocations[i].dispose();
  41907. this._liveLocations = [];
  41908.  
  41909. this._uiLocations = {};
  41910. },
  41911.  
  41912.  
  41913. _breakpointStorageId: function()
  41914. {
  41915. return this._sourceFileId + ":" + this._primaryUILocation.lineNumber;
  41916. },
  41917.  
  41918. _fakeBreakpointAtPrimaryLocation: function()
  41919. {
  41920. this._resetLocations();
  41921. this._uiLocations[""] = this._primaryUILocation;
  41922. this._breakpointManager._uiLocationAdded(this, this._primaryUILocation);
  41923. }
  41924. }
  41925.  
  41926.  
  41927. WebInspector.BreakpointManager.Storage = function(breakpointManager, setting)
  41928. {
  41929. this._breakpointManager = breakpointManager;
  41930. this._setting = setting;
  41931. var breakpoints = this._setting.get();
  41932.  
  41933. this._breakpoints = {};
  41934. for (var i = 0; i < breakpoints.length; ++i) {
  41935. var breakpoint =   (breakpoints[i]);
  41936. this._breakpoints[breakpoint.sourceFileId + ":" + breakpoint.lineNumber] = breakpoint;
  41937. }
  41938. }
  41939.  
  41940. WebInspector.BreakpointManager.Storage.prototype = {
  41941.  
  41942. _restoreBreakpoints: function(uiSourceCode)
  41943. {
  41944. this._muted = true;
  41945. var sourceFileId = WebInspector.BreakpointManager.sourceFileId(uiSourceCode);
  41946. for (var id in this._breakpoints) {
  41947. var breakpoint = this._breakpoints[id];
  41948. if (breakpoint.sourceFileId === sourceFileId)
  41949. this._breakpointManager._innerSetBreakpoint(uiSourceCode, breakpoint.lineNumber, breakpoint.condition, breakpoint.enabled);
  41950. }
  41951. delete this._muted;
  41952. },
  41953.  
  41954.  
  41955. _updateBreakpoint: function(breakpoint)
  41956. {
  41957. if (this._muted || !breakpoint._breakpointStorageId())
  41958. return;
  41959. this._breakpoints[breakpoint._breakpointStorageId()] = new WebInspector.BreakpointManager.Storage.Item(breakpoint);
  41960. this._save();
  41961. },
  41962.  
  41963.  
  41964. _removeBreakpoint: function(breakpoint)
  41965. {
  41966. if (this._muted)
  41967. return;
  41968. delete this._breakpoints[breakpoint._breakpointStorageId()];
  41969. this._save();
  41970. },
  41971.  
  41972. _save: function()
  41973. {
  41974. var breakpointsArray = [];
  41975. for (var id in this._breakpoints)
  41976. breakpointsArray.push(this._breakpoints[id]);
  41977. this._setting.set(breakpointsArray);
  41978. }
  41979. }
  41980.  
  41981.  
  41982. WebInspector.BreakpointManager.Storage.Item = function(breakpoint)
  41983. {
  41984. var primaryUILocation = breakpoint.primaryUILocation();
  41985. this.sourceFileId = breakpoint._sourceFileId;
  41986. this.lineNumber = primaryUILocation.lineNumber;
  41987. this.condition = breakpoint.condition();
  41988. this.enabled = breakpoint.enabled();
  41989. }
  41990.  
  41991.  
  41992. WebInspector.breakpointManager = null;
  41993.  
  41994.  
  41995.  
  41996.  
  41997.  
  41998.  
  41999. WebInspector.ConcatenatedScriptsContentProvider = function(scripts)
  42000. {
  42001. this._mimeType = "text/html";
  42002. this._scripts = scripts;
  42003. }
  42004.  
  42005. WebInspector.ConcatenatedScriptsContentProvider.scriptOpenTag = "<script>";
  42006. WebInspector.ConcatenatedScriptsContentProvider.scriptCloseTag = "</script>";
  42007.  
  42008. WebInspector.ConcatenatedScriptsContentProvider.prototype = {
  42009.  
  42010. _sortedScripts: function()
  42011. {
  42012. if (this._sortedScriptsArray)
  42013. return this._sortedScriptsArray;
  42014.  
  42015. this._sortedScriptsArray = [];
  42016.  
  42017. var scripts = this._scripts.slice();
  42018. scripts.sort(function(x, y) { return x.lineOffset - y.lineOffset || x.columnOffset - y.columnOffset; });
  42019.  
  42020. var scriptOpenTagLength = WebInspector.ConcatenatedScriptsContentProvider.scriptOpenTag.length;
  42021. var scriptCloseTagLength = WebInspector.ConcatenatedScriptsContentProvider.scriptCloseTag.length;
  42022.  
  42023. this._sortedScriptsArray.push(scripts[0]);
  42024. for (var i = 1; i < scripts.length; ++i) {
  42025. var previousScript = this._sortedScriptsArray[this._sortedScriptsArray.length - 1];
  42026.  
  42027. var lineNumber = previousScript.endLine;
  42028. var columnNumber = previousScript.endColumn + scriptCloseTagLength + scriptOpenTagLength;
  42029.  
  42030. if (lineNumber < scripts[i].lineOffset || (lineNumber === scripts[i].lineOffset && columnNumber <= scripts[i].columnOffset))
  42031. this._sortedScriptsArray.push(scripts[i]);
  42032. }
  42033. return this._sortedScriptsArray;
  42034. },
  42035.  
  42036.  
  42037. contentURL: function()
  42038. {
  42039. return "";
  42040. },
  42041.  
  42042.  
  42043. contentType: function()
  42044. {
  42045. return WebInspector.resourceTypes.Document;
  42046. },
  42047.  
  42048.  
  42049. requestContent: function(callback)
  42050. {
  42051. var scripts = this._sortedScripts();
  42052. var sources = [];
  42053. function didRequestSource(content, contentEncoded, mimeType)
  42054. {
  42055. sources.push(content);
  42056. if (sources.length == scripts.length)
  42057. callback(this._concatenateScriptsContent(scripts, sources), false, this._mimeType);
  42058. }
  42059. for (var i = 0; i < scripts.length; ++i)
  42060. scripts[i].requestContent(didRequestSource.bind(this));
  42061. },
  42062.  
  42063.  
  42064. searchInContent: function(query, caseSensitive, isRegex, callback)
  42065. {
  42066. var results = {};
  42067. var scripts = this._sortedScripts();
  42068. var scriptsLeft = scripts.length;
  42069.  
  42070. function maybeCallback()
  42071. {
  42072. if (scriptsLeft)
  42073. return;
  42074.  
  42075. var result = [];
  42076. for (var i = 0; i < scripts.length; ++i)
  42077. result = result.concat(results[scripts[i].scriptId]);
  42078. callback(result);
  42079. }
  42080.  
  42081.  
  42082. function searchCallback(script, searchMatches)
  42083. {
  42084. results[script.scriptId] = [];
  42085. for (var i = 0; i < searchMatches.length; ++i) {
  42086. var searchMatch = new WebInspector.ContentProvider.SearchMatch(searchMatches[i].lineNumber + script.lineOffset, searchMatches[i].lineContent);
  42087. results[script.scriptId].push(searchMatch);
  42088. }
  42089. scriptsLeft--;
  42090. maybeCallback.call(this);
  42091. }
  42092.  
  42093. maybeCallback();
  42094. for (var i = 0; i < scripts.length; ++i)
  42095. scripts[i].searchInContent(query, caseSensitive, isRegex, searchCallback.bind(this, scripts[i]));
  42096. },
  42097.  
  42098.  
  42099. _concatenateScriptsContent: function(scripts, sources)
  42100. {
  42101. var content = "";
  42102. var lineNumber = 0;
  42103. var columnNumber = 0;
  42104.  
  42105. var scriptOpenTag = WebInspector.ConcatenatedScriptsContentProvider.scriptOpenTag;
  42106. var scriptCloseTag = WebInspector.ConcatenatedScriptsContentProvider.scriptCloseTag;
  42107. for (var i = 0; i < scripts.length; ++i) {
  42108.  
  42109. for (var newLinesCount = scripts[i].lineOffset - lineNumber; newLinesCount > 0; --newLinesCount) {
  42110. columnNumber = 0;
  42111. content += "\n";
  42112. }
  42113. for (var spacesCount = scripts[i].columnOffset - columnNumber - scriptOpenTag.length; spacesCount > 0; --spacesCount)
  42114. content += " ";
  42115.  
  42116.  
  42117. content += scriptOpenTag;
  42118. content += sources[i];
  42119. content += scriptCloseTag;
  42120. lineNumber = scripts[i].endLine;
  42121. columnNumber = scripts[i].endColumn + scriptCloseTag.length;
  42122. }
  42123.  
  42124. return content;
  42125. },
  42126.  
  42127. __proto__: WebInspector.ContentProvider.prototype
  42128. }
  42129.  
  42130.  
  42131. WebInspector.CompilerSourceMappingContentProvider = function(sourceURL)
  42132. {
  42133. this._sourceURL = sourceURL;
  42134. }
  42135.  
  42136. WebInspector.CompilerSourceMappingContentProvider.prototype = {
  42137.  
  42138. contentURL: function()
  42139. {
  42140. return this._sourceURL;
  42141. },
  42142.  
  42143.  
  42144. contentType: function()
  42145. {
  42146. return WebInspector.resourceTypes.Script;
  42147. },
  42148.  
  42149.  
  42150. requestContent: function(callback)
  42151. {
  42152. var sourceCode = "";
  42153. try {
  42154.  
  42155. sourceCode = InspectorFrontendHost.loadResourceSynchronously(this._sourceURL);
  42156. } catch(e) {
  42157. console.error(e.message);
  42158. }
  42159. callback(sourceCode, false, "text/javascript");
  42160. },
  42161.  
  42162.  
  42163. searchInContent: function(query, caseSensitive, isRegex, callback)
  42164. {
  42165. callback([]);
  42166. },
  42167.  
  42168. __proto__: WebInspector.ContentProvider.prototype
  42169. }
  42170.  
  42171.  
  42172. WebInspector.StaticContentProvider = function(contentType, content, mimeType)
  42173. {
  42174. this._content = content;
  42175. this._contentType = contentType;
  42176. this._mimeType = mimeType;
  42177. }
  42178.  
  42179. WebInspector.StaticContentProvider.prototype = {
  42180.  
  42181. contentURL: function()
  42182. {
  42183. return "";
  42184. },
  42185.  
  42186.  
  42187. contentType: function()
  42188. {
  42189. return this._contentType;
  42190. },
  42191.  
  42192.  
  42193. requestContent: function(callback)
  42194. {
  42195. callback(this._content, false, this._mimeType || this._contentType.canonicalMimeType());
  42196. },
  42197.  
  42198.  
  42199. searchInContent: function(query, caseSensitive, isRegex, callback)
  42200. {
  42201. function performSearch()
  42202. {
  42203. var regex = createSearchRegex(query, caseSensitive, isRegex);
  42204.  
  42205. var result = [];
  42206. var lineEndings = this._content.lineEndings();
  42207. for (var i = 0; i < lineEndings.length; ++i) {
  42208. var lineStart = i > 0 ? lineEndings[i - 1] + 1 : 0;
  42209. var lineEnd = lineEndings[i];
  42210. var lineContent = this._content.substring(lineStart, lineEnd);
  42211. if (lineContent.length > 0 && lineContent.charAt(lineContent.length - 1) === "\r")
  42212. lineContent = lineContent.substring(0, lineContent.length - 1)
  42213.  
  42214. if (regex.exec(lineContent))
  42215. result.push(new WebInspector.ContentProvider.SearchMatch(i, lineContent));
  42216. }
  42217. callback(result);
  42218. }
  42219.  
  42220.  
  42221. window.setTimeout(performSearch.bind(this), 0);
  42222. },
  42223.  
  42224. __proto__: WebInspector.ContentProvider.prototype
  42225. }
  42226.  
  42227.  
  42228.  
  42229.  
  42230.  
  42231.  
  42232. WebInspector.ResourceScriptMapping = function(workspace)
  42233. {
  42234. this._workspace = workspace;
  42235. this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._reset, this);
  42236. this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, this._uiSourceCodeAddedToWorkspace, this);
  42237.  
  42238. this._reset();
  42239. }
  42240.  
  42241. WebInspector.ResourceScriptMapping.prototype = {
  42242.  
  42243. rawLocationToUILocation: function(rawLocation)
  42244. {
  42245. var debuggerModelLocation =   (rawLocation);
  42246. var script = WebInspector.debuggerModel.scriptForId(debuggerModelLocation.scriptId);
  42247. var uiSourceCode = this._workspaceUISourceCodeForScript(script) || this._getOrCreateTemporaryUISourceCode(script);
  42248. if (uiSourceCode.scriptFile() && uiSourceCode.scriptFile().hasDivergedFromVM())
  42249. uiSourceCode = this._getOrCreateOriginalUISourceCode(script, uiSourceCode);
  42250. console.assert(!!uiSourceCode);
  42251. return new WebInspector.UILocation(uiSourceCode, debuggerModelLocation.lineNumber, debuggerModelLocation.columnNumber || 0);
  42252. },
  42253.  
  42254.  
  42255. _hasMergedToVM: function(uiSourceCode)
  42256. {
  42257. var scripts = this._scriptsForUISourceCode(uiSourceCode);
  42258. if (!scripts.length)
  42259. return;
  42260. this._deleteOriginalUISourceCodeForScripts(scripts);
  42261. for (var i = 0; i < scripts.length; ++i)
  42262. scripts[i].setSourceMapping(this);
  42263. },
  42264.  
  42265.  
  42266. _hasDivergedFromVM: function(uiSourceCode)
  42267. {
  42268. var scripts = this._scriptsForUISourceCode(uiSourceCode);
  42269. if (!scripts.length)
  42270. return;
  42271. for (var i = 0; i < scripts.length; ++i)
  42272. scripts[i].setSourceMapping(this);
  42273. },
  42274.  
  42275.  
  42276. _workspaceUISourceCodeForScript: function(script)
  42277. {
  42278. if (script.isAnonymousScript() || this._isDynamicScript(script))
  42279. return null;
  42280. return this._workspace.uiSourceCodeForURL(script.sourceURL);
  42281. },
  42282.  
  42283.  
  42284. uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
  42285. {
  42286. var scripts = this._scriptsForUISourceCode(uiSourceCode);
  42287. console.assert(scripts.length);
  42288. return WebInspector.debuggerModel.createRawLocation(scripts[0], lineNumber, columnNumber);
  42289. },
  42290.  
  42291.  
  42292. addScript: function(script)
  42293. {
  42294. if (!script.isAnonymousScript()) {
  42295. this._scripts.push(script);
  42296. var scriptsForSourceURL = script.isInlineScript() ? this._inlineScriptsForSourceURL : this._nonInlineScriptsForSourceURL;
  42297. var bucket = scriptsForSourceURL[script.sourceURL] || [];
  42298. scriptsForSourceURL[script.sourceURL] = bucket;
  42299. bucket.push(script);
  42300. }
  42301.  
  42302. script.setSourceMapping(this);
  42303. var uiSourceCode = this._workspaceUISourceCodeForScript(script);
  42304. if (uiSourceCode) {
  42305. this._bindUISourceCodeToScripts(uiSourceCode, [script]);
  42306. return;
  42307. }
  42308.  
  42309. var scripts = script.isInlineScript() ? this._scriptsForSourceURL(script.sourceURL, true) : [script];
  42310.  
  42311. if (this._deleteTemporaryUISourceCodeForScripts(scripts)) {
  42312. this._deleteOriginalUISourceCodeForScripts(scripts);
  42313. this._getOrCreateTemporaryUISourceCode(script);
  42314. }
  42315. },
  42316.  
  42317.  
  42318. _deleteOriginalUISourceCodeForScripts: function(scripts)
  42319. {
  42320. var originalUISourceCode;
  42321. for (var i = 0; i < scripts.length; ++i) {
  42322. originalUISourceCode = originalUISourceCode || this._originalUISourceCodeForScriptId[scripts[i].scriptId];
  42323. delete this._originalUISourceCodeForScriptId[scripts[i].scriptId];
  42324. }
  42325. if (!originalUISourceCode)
  42326. return;
  42327. this._workspace.removeTemporaryUISourceCode(originalUISourceCode);
  42328. this._scriptIdsForOriginalUISourceCode.remove(originalUISourceCode);
  42329. },
  42330.  
  42331.  
  42332. _deleteTemporaryUISourceCodeForScripts: function(scripts)
  42333. {
  42334. var temporaryUISourceCode;
  42335. for (var i = 0; i < scripts.length; ++i) {
  42336. temporaryUISourceCode = temporaryUISourceCode || this._temporaryUISourceCodeForScriptId[scripts[i].scriptId];
  42337. delete this._temporaryUISourceCodeForScriptId[scripts[i].scriptId];
  42338. }
  42339. if (!temporaryUISourceCode)
  42340. return false;
  42341. this._workspace.removeTemporaryUISourceCode(temporaryUISourceCode);
  42342. this._scriptIdsForTemporaryUISourceCode.remove(temporaryUISourceCode);
  42343. return true;
  42344. },
  42345.  
  42346.  
  42347. _bindUISourceCodeToScripts: function(uiSourceCode, scripts)
  42348. {
  42349. console.assert(scripts.length);
  42350. if (uiSourceCode.isEditable()) {
  42351. var scriptFile = new WebInspector.ResourceScriptFile(this, uiSourceCode);
  42352. uiSourceCode.setScriptFile(scriptFile);
  42353. }
  42354. for (var i = 0; i < scripts.length; ++i)
  42355. scripts[i].setSourceMapping(this);
  42356. uiSourceCode.setSourceMapping(this);
  42357. },
  42358.  
  42359.  
  42360. _isDynamicScript: function(script)
  42361. {
  42362. if (script.isAnonymousScript() || script.isInlineScript())
  42363. return false;
  42364. var inlineScriptsWithTheSameURL = this._scriptsForSourceURL(script.sourceURL, true);
  42365. return !!inlineScriptsWithTheSameURL.length;
  42366. },
  42367.  
  42368.  
  42369. _scriptsForSourceURL: function(sourceURL, isInlineScript)
  42370. {
  42371. var scriptsForSourceURL = isInlineScript ? this._inlineScriptsForSourceURL : this._nonInlineScriptsForSourceURL;
  42372. return scriptsForSourceURL[sourceURL] || [];
  42373. },
  42374.  
  42375.  
  42376. _createUISourceCode: function(scripts, divergedVersion)
  42377. {
  42378. var script = scripts[0];
  42379. var contentProvider = script.isInlineScript() ? new WebInspector.ConcatenatedScriptsContentProvider(scripts.slice()) : script;
  42380. var isDynamicScript = this._isDynamicScript(script);
  42381. var url = isDynamicScript ? "" : script.sourceURL;
  42382. var temporaryUISourceCode = this._workspace.addTemporaryUISourceCode(url, contentProvider, !script.isInlineScript() && !divergedVersion, script.isContentScript);
  42383. temporaryUISourceCode.divergedVersion = divergedVersion;
  42384. return temporaryUISourceCode;
  42385. },
  42386.  
  42387.  
  42388. _getOrCreateTemporaryUISourceCode: function(script)
  42389. {
  42390. var temporaryUISourceCode = this._temporaryUISourceCodeForScriptId[script.scriptId];
  42391. if (temporaryUISourceCode)
  42392. return temporaryUISourceCode;
  42393.  
  42394. var scripts = script.isInlineScript() ? this._scriptsForSourceURL(script.sourceURL, true) : [script];
  42395. temporaryUISourceCode = this._createUISourceCode(scripts);
  42396. var scriptIds = [];
  42397. for (var i = 0; i < scripts.length; ++i) {
  42398. this._temporaryUISourceCodeForScriptId[scripts[i].scriptId] = temporaryUISourceCode;
  42399. scriptIds.push(scripts[i].scriptId);
  42400. }
  42401. this._scriptIdsForTemporaryUISourceCode.put(temporaryUISourceCode, scriptIds);
  42402. this._bindUISourceCodeToScripts(temporaryUISourceCode, scripts);
  42403. return temporaryUISourceCode;
  42404. },
  42405.  
  42406.  
  42407. _getOrCreateOriginalUISourceCode: function(script, divergedVersion)
  42408. {
  42409. var originalUISourceCode = this._originalUISourceCodeForScriptId[script.scriptId];
  42410. if (originalUISourceCode)
  42411. return originalUISourceCode;
  42412.  
  42413. var scripts = script.isInlineScript() ? this._scriptsForSourceURL(script.sourceURL, true) : [script];
  42414. originalUISourceCode = this._createUISourceCode(scripts, divergedVersion);
  42415. var scriptIds = [];
  42416. for (var i = 0; i < scripts.length; ++i) {
  42417. this._originalUISourceCodeForScriptId[scripts[i].scriptId] = originalUISourceCode;
  42418. scriptIds.push(scripts[i].scriptId);
  42419. }
  42420. this._scriptIdsForOriginalUISourceCode.put(originalUISourceCode, scriptIds);
  42421. this._bindUISourceCodeToScripts(originalUISourceCode, scripts);
  42422. return originalUISourceCode;
  42423. },
  42424.  
  42425. _uiSourceCodeAddedToWorkspace: function(event)
  42426. {
  42427. var uiSourceCode =   (event.data);
  42428. console.assert(!!uiSourceCode.url);
  42429.  
  42430. var scripts = this._scriptsForUISourceCode(uiSourceCode);
  42431. if (!scripts.length)
  42432. return;
  42433.  
  42434. this._deleteTemporaryUISourceCodeForScripts(scripts);
  42435. this._deleteOriginalUISourceCodeForScripts(scripts);
  42436. this._bindUISourceCodeToScripts(uiSourceCode, scripts);
  42437. },
  42438.  
  42439.  
  42440. _scriptsForUISourceCode: function(uiSourceCode)
  42441. {
  42442. var scriptIds = this._scriptIdsForOriginalUISourceCode.get(uiSourceCode) || this._scriptIdsForTemporaryUISourceCode.get(uiSourceCode);
  42443. if (scriptIds)
  42444. return scriptIds.map(WebInspector.debuggerModel.scriptForId.bind(WebInspector.debuggerModel));
  42445.  
  42446. var isInlineScript;
  42447. switch (uiSourceCode.contentType()) {
  42448. case WebInspector.resourceTypes.Document:
  42449. isInlineScript = true;
  42450. break;
  42451. case WebInspector.resourceTypes.Script:
  42452. isInlineScript = false;
  42453. break;
  42454. default:
  42455. return [];
  42456. }
  42457. return this._scriptsForSourceURL(uiSourceCode.url, isInlineScript);
  42458. },
  42459.  
  42460. _reset: function()
  42461. {
  42462.  
  42463. this._temporaryUISourceCodeForScriptId = {};
  42464. this._scriptIdsForTemporaryUISourceCode = new Map();
  42465.  
  42466. this._originalUISourceCodeForScriptId = {};
  42467. this._scriptIdsForOriginalUISourceCode = new Map();
  42468.  
  42469. this._inlineScriptsForSourceURL = {};
  42470.  
  42471. this._nonInlineScriptsForSourceURL = {};
  42472. this._scripts = [];
  42473. },
  42474. }
  42475.  
  42476.  
  42477. WebInspector.ScriptFile = function()
  42478. {
  42479. }
  42480.  
  42481. WebInspector.ScriptFile.Events = {
  42482. WillMergeToVM: "WillMergeToVM",
  42483. DidMergeToVM: "DidMergeToVM",
  42484. WillDivergeFromVM: "WillDivergeFromVM",
  42485. DidDivergeFromVM: "DidDivergeFromVM",
  42486. }
  42487.  
  42488. WebInspector.ScriptFile.prototype = {
  42489.  
  42490. hasDivergedFromVM: function() { return false; },
  42491.  
  42492.  
  42493. isDivergingFromVM: function() { return false; },
  42494.  
  42495.  
  42496. addEventListener: function(eventType, listener, thisObject) { },
  42497.  
  42498.  
  42499. removeEventListener: function(eventType, listener, thisObject) { }
  42500. }
  42501.  
  42502.  
  42503. WebInspector.ResourceScriptFile = function(resourceScriptMapping, uiSourceCode)
  42504. {
  42505. WebInspector.ScriptFile.call(this);
  42506. this._resourceScriptMapping = resourceScriptMapping;
  42507. this._uiSourceCode = uiSourceCode;
  42508. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCommitted, this);
  42509. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChanged, this);
  42510. }
  42511.  
  42512. WebInspector.ResourceScriptFile.prototype = {
  42513. _workingCopyCommitted: function(event)
  42514. {
  42515.  
  42516. function innerCallback(error)
  42517. {
  42518. if (error) {
  42519. this._hasDivergedFromVM = true;
  42520. WebInspector.showErrorMessage(error);
  42521. return;
  42522. }
  42523.  
  42524. this.dispatchEventToListeners(WebInspector.ScriptFile.Events.WillMergeToVM, this);
  42525. delete this._hasDivergedFromVM;
  42526. this._resourceScriptMapping._hasMergedToVM(this._uiSourceCode);
  42527. this.dispatchEventToListeners(WebInspector.ScriptFile.Events.DidMergeToVM, this);
  42528. }
  42529.  
  42530. var rawLocation =   (this._uiSourceCode.uiLocationToRawLocation(0, 0));
  42531. if (!rawLocation)
  42532. return;
  42533. var script = WebInspector.debuggerModel.scriptForId(rawLocation.scriptId);
  42534. WebInspector.debuggerModel.setScriptSource(script.scriptId, this._uiSourceCode.workingCopy(), innerCallback.bind(this));
  42535. },
  42536.  
  42537. _workingCopyChanged: function(event)
  42538. {
  42539. var wasDirty =   (event.data.wasDirty);
  42540. if (!wasDirty && this._uiSourceCode.isDirty() && !this._hasDivergedFromVM) {
  42541. this._isDivergingFromVM = true;
  42542. this.dispatchEventToListeners(WebInspector.ScriptFile.Events.WillDivergeFromVM, this._uiSourceCode);
  42543. this._resourceScriptMapping._hasDivergedFromVM(this._uiSourceCode);
  42544. this.dispatchEventToListeners(WebInspector.ScriptFile.Events.DidDivergeFromVM, this._uiSourceCode);
  42545. delete this._isDivergingFromVM;
  42546. } else if (wasDirty && !this._uiSourceCode.isDirty() && !this._hasDivergedFromVM) {
  42547. this.dispatchEventToListeners(WebInspector.ScriptFile.Events.WillMergeToVM, this._uiSourceCode);
  42548. this._resourceScriptMapping._hasMergedToVM(this._uiSourceCode);
  42549. this.dispatchEventToListeners(WebInspector.ScriptFile.Events.DidMergeToVM, this._uiSourceCode);
  42550. }
  42551. },
  42552.  
  42553.  
  42554. hasDivergedFromVM: function()
  42555. {
  42556. return this._uiSourceCode.isDirty() || this._hasDivergedFromVM;
  42557. },
  42558.  
  42559.  
  42560. isDivergingFromVM: function()
  42561. {
  42562. return this._isDivergingFromVM;
  42563. },
  42564.  
  42565. __proto__: WebInspector.Object.prototype
  42566. }
  42567.  
  42568.  
  42569.  
  42570.  
  42571.  
  42572.  
  42573. WebInspector.CompilerScriptMapping = function(workspace, networkWorkspaceProvider)
  42574. {
  42575. this._workspace = workspace;
  42576. this._networkWorkspaceProvider = networkWorkspaceProvider;
  42577.  
  42578. this._sourceMapForSourceMapURL = {};
  42579.  
  42580. this._sourceMapForScriptId = {};
  42581. this._scriptForSourceMap = new Map();
  42582.  
  42583. this._sourceMapForURL = {};
  42584.  
  42585. this._originalUISourceCodeForScriptId = {};
  42586. this._scriptForOriginalUISourceCode = new Map();
  42587. this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._reset, this);
  42588. }
  42589.  
  42590. WebInspector.CompilerScriptMapping.prototype = {
  42591.  
  42592. rawLocationToUILocation: function(rawLocation)
  42593. {
  42594. var debuggerModelLocation =   (rawLocation);
  42595. var sourceMap = this._sourceMapForScriptId[debuggerModelLocation.scriptId];
  42596. var lineNumber = debuggerModelLocation.lineNumber;
  42597. var columnNumber = debuggerModelLocation.columnNumber || 0;
  42598. var entry = sourceMap.findEntry(lineNumber, columnNumber);
  42599. if (entry.length === 2) {
  42600. var temporaryUISourceCode = this._originalUISourceCodeForScriptId[debuggerModelLocation.scriptId];
  42601. return new WebInspector.UILocation(temporaryUISourceCode, lineNumber, columnNumber);
  42602. }
  42603. var uiSourceCode = this._workspace.uiSourceCodeForURL(entry[2]);
  42604. return new WebInspector.UILocation(uiSourceCode, entry[3], entry[4]);
  42605. },
  42606.  
  42607.  
  42608. uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
  42609. {
  42610. var script = this._scriptForOriginalUISourceCode.get(uiSourceCode);
  42611. if (script)
  42612. return WebInspector.debuggerModel.createRawLocation(script, lineNumber, columnNumber);
  42613. var sourceMap = this._sourceMapForURL[uiSourceCode.url];
  42614. var entry = sourceMap.findEntryReversed(uiSourceCode.url, lineNumber);
  42615. return WebInspector.debuggerModel.createRawLocation(this._scriptForSourceMap.get(sourceMap), entry[0], entry[1]);
  42616. },
  42617.  
  42618.  
  42619. addScript: function(script)
  42620. {
  42621.  
  42622.  
  42623. var originalUISourceCode = this._workspace.addTemporaryUISourceCode(script.sourceURL, script, false);
  42624. originalUISourceCode.setSourceMapping(this);
  42625. this._originalUISourceCodeForScriptId[script.scriptId] = originalUISourceCode;
  42626. this._scriptForOriginalUISourceCode.put(originalUISourceCode, script);
  42627.  
  42628. var sourceMap = this.loadSourceMapForScript(script);
  42629.  
  42630. if (this._scriptForSourceMap.get(sourceMap)) {
  42631. this._sourceMapForScriptId[script.scriptId] = sourceMap;
  42632. script.setSourceMapping(this);
  42633. return;
  42634. }
  42635.  
  42636. var sourceURLs = sourceMap.sources();
  42637. for (var i = 0; i < sourceURLs.length; ++i) {
  42638. var sourceURL = sourceURLs[i];
  42639. if (this._workspace.uiSourceCodeForURL(sourceURL))
  42640. continue;
  42641. this._sourceMapForURL[sourceURL] = sourceMap;
  42642. var sourceContent = sourceMap.sourceContent(sourceURL);
  42643. var contentProvider;
  42644. if (sourceContent)
  42645. contentProvider = new WebInspector.StaticContentProvider(WebInspector.resourceTypes.Script, sourceContent);
  42646. else
  42647. contentProvider = new WebInspector.CompilerSourceMappingContentProvider(sourceURL);
  42648. this._networkWorkspaceProvider.addFile(sourceURL, contentProvider, true);
  42649. var uiSourceCode = this._workspace.uiSourceCodeForURL(sourceURL);
  42650. uiSourceCode.setSourceMapping(this);
  42651. uiSourceCode.isContentScript = script.isContentScript;
  42652. }
  42653.  
  42654. this._sourceMapForScriptId[script.scriptId] = sourceMap;
  42655. this._scriptForSourceMap.put(sourceMap, script);
  42656. script.setSourceMapping(this);
  42657. },
  42658.  
  42659.  
  42660. loadSourceMapForScript: function(script)
  42661. {
  42662. var sourceMapURL = WebInspector.SourceMapParser.prototype._canonicalizeURL(script.sourceMapURL, script.sourceURL);
  42663. var sourceMap = this._sourceMapForSourceMapURL[sourceMapURL];
  42664. if (sourceMap)
  42665. return sourceMap;
  42666.  
  42667. try {
  42668.  
  42669. var response = InspectorFrontendHost.loadResourceSynchronously(sourceMapURL);
  42670. if (response.slice(0, 3) === ")]}")
  42671. response = response.substring(response.indexOf('\n'));
  42672. var payload =   (JSON.parse(response));
  42673. sourceMap = new WebInspector.SourceMapParser(sourceMapURL, payload);
  42674. } catch(e) {
  42675. console.error(e.message);
  42676. return null;
  42677. }
  42678. this._sourceMapForSourceMapURL[sourceMapURL] = sourceMap;
  42679. return sourceMap;
  42680. },
  42681.  
  42682. _reset: function()
  42683. {
  42684. this._sourceMapForSourceMapURL = {};
  42685. this._sourceMapForScriptId = {};
  42686. this._scriptForSourceMap = new Map();
  42687. this._sourceMapForURL = {};
  42688. this._originalUISourceCodeForScriptId = {};
  42689. this._scriptForOriginalUISourceCode = new Map();
  42690. }
  42691. }
  42692.  
  42693.  
  42694. WebInspector.SourceMapPayload = function()
  42695. {
  42696. this.sections = [];
  42697. this.mappings = "";
  42698. this.sourceRoot = "";
  42699. this.sources = [];
  42700. }
  42701.  
  42702.  
  42703. WebInspector.SourceMapParser = function(sourceMappingURL, payload)
  42704. {
  42705. if (!WebInspector.SourceMapParser.prototype._base64Map) {
  42706. const base64Digits = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  42707. WebInspector.SourceMapParser.prototype._base64Map = {};
  42708. for (var i = 0; i < base64Digits.length; ++i)
  42709. WebInspector.SourceMapParser.prototype._base64Map[base64Digits.charAt(i)] = i;
  42710. }
  42711.  
  42712. this._sourceMappingURL = sourceMappingURL;
  42713. this._mappings = [];
  42714. this._reverseMappingsBySourceURL = {};
  42715. this._sourceContentByURL = {};
  42716. this._parseMappingPayload(payload);
  42717. }
  42718.  
  42719. WebInspector.SourceMapParser.prototype = {
  42720.  
  42721. sources: function()
  42722. {
  42723. var sources = [];
  42724. for (var sourceURL in this._reverseMappingsBySourceURL)
  42725. sources.push(sourceURL);
  42726. return sources;
  42727. },
  42728.  
  42729. sourceContent: function(sourceURL)
  42730. {
  42731. return this._sourceContentByURL[sourceURL];
  42732. },
  42733.  
  42734. findEntry: function(lineNumber, columnNumber)
  42735. {
  42736. var first = 0;
  42737. var count = this._mappings.length;
  42738. while (count > 1) {
  42739. var step = count >> 1;
  42740. var middle = first + step;
  42741. var mapping = this._mappings[middle];
  42742. if (lineNumber < mapping[0] || (lineNumber == mapping[0] && columnNumber < mapping[1]))
  42743. count = step;
  42744. else {
  42745. first = middle;
  42746. count -= step;
  42747. }
  42748. }
  42749. return this._mappings[first];
  42750. },
  42751.  
  42752. findEntryReversed: function(sourceURL, lineNumber)
  42753. {
  42754. var mappings = this._reverseMappingsBySourceURL[sourceURL];
  42755. for ( ; lineNumber < mappings.length; ++lineNumber) {
  42756. var mapping = mappings[lineNumber];
  42757. if (mapping)
  42758. return mapping;
  42759. }
  42760. return this._mappings[0];
  42761. },
  42762.  
  42763. _parseMappingPayload: function(mappingPayload)
  42764. {
  42765. if (mappingPayload.sections)
  42766. this._parseSections(mappingPayload.sections);
  42767. else
  42768. this._parseMap(mappingPayload, 0, 0);
  42769. },
  42770.  
  42771.  
  42772. _parseSections: function(sections)
  42773. {
  42774. for (var i = 0; i < sections.length; ++i) {
  42775. var section = sections[i];
  42776. this._parseMap(section.map, section.offset.line, section.offset.column)
  42777. }
  42778. },
  42779.  
  42780.  
  42781. _parseMap: function(map, lineNumber, columnNumber)
  42782. {
  42783. var sourceIndex = 0;
  42784. var sourceLineNumber = 0;
  42785. var sourceColumnNumber = 0;
  42786. var nameIndex = 0;
  42787.  
  42788. var sources = [];
  42789. for (var i = 0; i < map.sources.length; ++i) {
  42790. var sourceURL = map.sources[i];
  42791. if (map.sourceRoot)
  42792. sourceURL = map.sourceRoot + "/" + sourceURL;
  42793. var url = this._canonicalizeURL(sourceURL, this._sourceMappingURL);
  42794. sources.push(url);
  42795. if (!this._reverseMappingsBySourceURL[url])
  42796. this._reverseMappingsBySourceURL[url] = [];
  42797. if (map.sourcesContent && map.sourcesContent[i])
  42798. this._sourceContentByURL[url] = map.sourcesContent[i];
  42799. }
  42800.  
  42801. var stringCharIterator = new WebInspector.SourceMapParser.StringCharIterator(map.mappings);
  42802. var sourceURL = sources[sourceIndex];
  42803. var reverseMappings = this._reverseMappingsBySourceURL[sourceURL];
  42804.  
  42805. while (true) {
  42806. if (stringCharIterator.peek() === ",")
  42807. stringCharIterator.next();
  42808. else {
  42809. while (stringCharIterator.peek() === ";") {
  42810. lineNumber += 1;
  42811. columnNumber = 0;
  42812. stringCharIterator.next();
  42813. }
  42814. if (!stringCharIterator.hasNext())
  42815. break;
  42816. }
  42817.  
  42818. columnNumber += this._decodeVLQ(stringCharIterator);
  42819. if (this._isSeparator(stringCharIterator.peek())) {
  42820. this._mappings.push([lineNumber, columnNumber]);
  42821. continue;
  42822. }
  42823.  
  42824. var sourceIndexDelta = this._decodeVLQ(stringCharIterator);
  42825. if (sourceIndexDelta) {
  42826. sourceIndex += sourceIndexDelta;
  42827. sourceURL = sources[sourceIndex];
  42828. reverseMappings = this._reverseMappingsBySourceURL[sourceURL];
  42829. }
  42830. sourceLineNumber += this._decodeVLQ(stringCharIterator);
  42831. sourceColumnNumber += this._decodeVLQ(stringCharIterator);
  42832. if (!this._isSeparator(stringCharIterator.peek()))
  42833. nameIndex += this._decodeVLQ(stringCharIterator);
  42834.  
  42835. this._mappings.push([lineNumber, columnNumber, sourceURL, sourceLineNumber, sourceColumnNumber]);
  42836. if (!reverseMappings[sourceLineNumber])
  42837. reverseMappings[sourceLineNumber] = [lineNumber, columnNumber];
  42838. }
  42839. },
  42840.  
  42841. _isSeparator: function(char)
  42842. {
  42843. return char === "," || char === ";";
  42844. },
  42845.  
  42846. _decodeVLQ: function(stringCharIterator)
  42847. {
  42848.  
  42849. var result = 0;
  42850. var shift = 0;
  42851. do {
  42852. var digit = this._base64Map[stringCharIterator.next()];
  42853. result += (digit & this._VLQ_BASE_MASK) << shift;
  42854. shift += this._VLQ_BASE_SHIFT;
  42855. } while (digit & this._VLQ_CONTINUATION_MASK);
  42856.  
  42857.  
  42858. var negative = result & 1;
  42859. result >>= 1;
  42860. return negative ? -result : result;
  42861. },
  42862.  
  42863. _canonicalizeURL: function(url, baseURL)
  42864. {
  42865. if (!url || !baseURL || url.asParsedURL() || url.substring(0, 5) === "data:")
  42866. return url;
  42867.  
  42868. var base = baseURL.asParsedURL();
  42869. if (!base)
  42870. return url;
  42871.  
  42872. var baseHost = base.scheme + "://" + base.host + (base.port ? ":" + base.port : "");
  42873. if (url[0] === "/")
  42874. return baseHost + url;
  42875. return baseHost + base.folderPathComponents + "/" + url;
  42876. },
  42877.  
  42878. _VLQ_BASE_SHIFT: 5,
  42879. _VLQ_BASE_MASK: (1 << 5) - 1,
  42880. _VLQ_CONTINUATION_MASK: 1 << 5
  42881. }
  42882.  
  42883.  
  42884. WebInspector.SourceMapParser.StringCharIterator = function(string)
  42885. {
  42886. this._string = string;
  42887. this._position = 0;
  42888. }
  42889.  
  42890. WebInspector.SourceMapParser.StringCharIterator.prototype = {
  42891. next: function()
  42892. {
  42893. return this._string.charAt(this._position++);
  42894. },
  42895.  
  42896. peek: function()
  42897. {
  42898. return this._string.charAt(this._position);
  42899. },
  42900.  
  42901. hasNext: function()
  42902. {
  42903. return this._position < this._string.length;
  42904. }
  42905. }
  42906.  
  42907.  
  42908.  
  42909.  
  42910.  
  42911.  
  42912. WebInspector.SASSSourceMapping = function(workspace, networkWorkspaceProvider)
  42913. {
  42914. this._workspace = workspace;
  42915. this._networkWorkspaceProvider = networkWorkspaceProvider;
  42916. this._uiLocations = {};
  42917. this._cssURLsForSASSURL = {};
  42918. this._timeoutForURL = {};
  42919. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, this._resourceAdded, this);
  42920. WebInspector.fileManager.addEventListener(WebInspector.FileManager.EventTypes.SavedURL, this._fileSaveFinished, this);
  42921. this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._reset, this);
  42922. }
  42923.  
  42924. WebInspector.SASSSourceMapping.prototype = {
  42925. _populate: function()
  42926. {
  42927. function populateFrame(frame)
  42928. {
  42929. for (var i = 0; i < frame.childFrames.length; ++i)
  42930. populateFrame.call(this, frame.childFrames[i]);
  42931.  
  42932. var resources = frame.resources();
  42933. for (var i = 0; i < resources.length; ++i)
  42934. this._resourceAdded({data:resources[i]});
  42935. }
  42936.  
  42937. populateFrame.call(this, WebInspector.resourceTreeModel.mainFrame);
  42938. },
  42939.  
  42940.  
  42941. _fileSaveFinished: function(event)
  42942. {
  42943. var sassURL =   (event.data);
  42944. function callback()
  42945. {
  42946. delete this._timeoutForURL[sassURL];
  42947. var cssURLs = this._cssURLsForSASSURL[sassURL];
  42948. if (!cssURLs)
  42949. return;
  42950. for (var i = 0; i < cssURLs.length; ++i)
  42951. this._reloadCSS(cssURLs[i]);
  42952. }
  42953.  
  42954. var timer = this._timeoutForURL[sassURL];
  42955. if (timer) {
  42956. clearTimeout(timer);
  42957. delete this._timeoutForURL[sassURL];
  42958. }
  42959. if (!WebInspector.settings.cssReloadEnabled.get() || !this._cssURLsForSASSURL[sassURL])
  42960. return;
  42961. var timeout = WebInspector.settings.cssReloadTimeout.get();
  42962. if (timeout && isFinite(timeout))
  42963. this._timeoutForURL[sassURL] = setTimeout(callback.bind(this), Number(timeout));
  42964. },
  42965.  
  42966. _reloadCSS: function(url)
  42967. {
  42968. var uiSourceCode = this._workspace.uiSourceCodeForURL(url);
  42969. if (!uiSourceCode)
  42970. return;
  42971. var newContent = InspectorFrontendHost.loadResourceSynchronously(url);
  42972. uiSourceCode.addRevision(newContent);
  42973. },
  42974.  
  42975.  
  42976. _resourceAdded: function(event)
  42977. {
  42978. var resource =   (event.data);
  42979. if (resource.type !== WebInspector.resourceTypes.Stylesheet)
  42980. return;
  42981.  
  42982.  
  42983. function didRequestContent(content, contentEncoded, mimeType)
  42984. {
  42985. if (!content)
  42986. return;
  42987. var lines = content.split(/\r?\n/);
  42988. var debugInfoRegex = /@media\s\-sass\-debug\-info{filename{font-family:([^}]+)}line{font-family:\\0000(\d\d)([^}]*)}}/i;
  42989.             var lineNumbersRegex = /\/\*\s+line\s+([0-9]+),\s+([^*\/]+)/;
  42990. for (var lineNumber = 0; lineNumber < lines.length; ++lineNumber) {
  42991. var match = debugInfoRegex.exec(lines[lineNumber]);
  42992. if (match) {
  42993. var url = match[1].replace(/\\(.)/g, "$1");
  42994. var line = parseInt(decodeURI("%" + match[2]) + match[3], 10);
  42995. this._bindUISourceCode(url, line, resource.url, lineNumber);
  42996. continue;
  42997. }
  42998. match = lineNumbersRegex.exec(lines[lineNumber]);
  42999. if (match) {
  43000. var fileName = match[2].trim();
  43001. var line = parseInt(match[1], 10);
  43002. var url = resource.url;
  43003. if (url.endsWith("/" + resource.parsedURL.lastPathComponent))
  43004. url = url.substring(0, url.length - resource.parsedURL.lastPathComponent.length) + fileName;
  43005. else
  43006. url = fileName;
  43007. this._bindUISourceCode(url, line, resource.url, lineNumber);
  43008. continue;
  43009. }
  43010. }
  43011. }
  43012. resource.requestContent(didRequestContent.bind(this));
  43013. },
  43014.  
  43015.  
  43016. _bindUISourceCode: function(url, line, rawURL, rawLine)
  43017. {
  43018. var uiSourceCode = this._workspace.uiSourceCodeForURL(url);
  43019. if (!uiSourceCode) {
  43020. var content = InspectorFrontendHost.loadResourceSynchronously(url);
  43021. var contentProvider = new WebInspector.StaticContentProvider(WebInspector.resourceTypes.Stylesheet, content, "text/x-scss");
  43022. this._networkWorkspaceProvider.addFile(url, contentProvider, true);
  43023. uiSourceCode = this._workspace.uiSourceCodeForURL(url);
  43024. WebInspector.cssModel.setSourceMapping(rawURL, this);
  43025. }
  43026. var rawLocationString = rawURL + ":" + (rawLine + 1);  
  43027. this._uiLocations[rawLocationString] = new WebInspector.UILocation(uiSourceCode, line - 1, 0);
  43028. this._addCSSURLforSASSURL(rawURL, url);
  43029. },
  43030.  
  43031.  
  43032. _addCSSURLforSASSURL: function(cssURL, sassURL)
  43033. {
  43034. var cssURLs;
  43035. if (this._cssURLsForSASSURL.hasOwnProperty(sassURL))
  43036. cssURLs = this._cssURLsForSASSURL[sassURL];
  43037. else {
  43038. cssURLs = [];
  43039. this._cssURLsForSASSURL[sassURL] = cssURLs;
  43040. }
  43041. if (cssURLs.indexOf(cssURL) === -1)
  43042. cssURLs.push(cssURL);
  43043. },
  43044.  
  43045.  
  43046. rawLocationToUILocation: function(rawLocation)
  43047. {
  43048. var location =   (rawLocation);
  43049. var uiLocation = this._uiLocations[location.url + ":" + location.lineNumber];
  43050. if (!uiLocation) {
  43051. var uiSourceCode = this._workspace.uiSourceCodeForURL(location.url);
  43052. uiLocation = new WebInspector.UILocation(uiSourceCode, location.lineNumber, 0);
  43053. }
  43054. return uiLocation;
  43055. },
  43056.  
  43057.  
  43058. uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
  43059. {
  43060.  
  43061. return new WebInspector.CSSLocation(uiSourceCode.contentURL() || "", lineNumber);
  43062. },
  43063.  
  43064. _reset: function()
  43065. {
  43066. this._uiLocations = {};
  43067. this._populate();
  43068. }
  43069. }
  43070.  
  43071.  
  43072.  
  43073.  
  43074.  
  43075.  
  43076.  
  43077. WebInspector.DOMNode = function(domAgent, doc, isInShadowTree, payload) {
  43078. this._domAgent = domAgent;
  43079. this.ownerDocument = doc;
  43080. this._isInShadowTree = isInShadowTree;
  43081.  
  43082. this.id = payload.nodeId;
  43083. domAgent._idToDOMNode[this.id] = this;
  43084. this._nodeType = payload.nodeType;
  43085. this._nodeName = payload.nodeName;
  43086. this._localName = payload.localName;
  43087. this._nodeValue = payload.nodeValue;
  43088.  
  43089. this._shadowRoots = [];
  43090.  
  43091. this._attributes = [];
  43092. this._attributesMap = {};
  43093. if (payload.attributes)
  43094. this._setAttributesPayload(payload.attributes);
  43095.  
  43096. this._userProperties = {};
  43097. this._descendantUserPropertyCounters = {};
  43098.  
  43099. this._childNodeCount = payload.childNodeCount;
  43100. this.children = null;
  43101.  
  43102. this.nextSibling = null;
  43103. this.previousSibling = null;
  43104. this.firstChild = null;
  43105. this.lastChild = null;
  43106. this.parentNode = null;
  43107.  
  43108. if (payload.shadowRoots && WebInspector.settings.showShadowDOM.get()) {
  43109. for (var i = 0; i < payload.shadowRoots.length; ++i) {
  43110. var root = payload.shadowRoots[i];
  43111. var node = new WebInspector.DOMNode(this._domAgent, this.ownerDocument, true, root);
  43112. this._shadowRoots.push(node);
  43113. }
  43114. }
  43115.  
  43116. if (payload.children)
  43117. this._setChildrenPayload(payload.children);
  43118.  
  43119. if (payload.contentDocument) {
  43120. this._contentDocument = new WebInspector.DOMDocument(domAgent, payload.contentDocument);
  43121. this.children = [this._contentDocument];
  43122. this._renumber();
  43123. }
  43124.  
  43125. if (this._nodeType === Node.ELEMENT_NODE) {
  43126.  
  43127. if (this.ownerDocument && !this.ownerDocument.documentElement && this._nodeName === "HTML")
  43128. this.ownerDocument.documentElement = this;
  43129. if (this.ownerDocument && !this.ownerDocument.body && this._nodeName === "BODY")
  43130. this.ownerDocument.body = this;
  43131. } else if (this._nodeType === Node.DOCUMENT_TYPE_NODE) {
  43132. this.publicId = payload.publicId;
  43133. this.systemId = payload.systemId;
  43134. this.internalSubset = payload.internalSubset;
  43135. } else if (this._nodeType === Node.ATTRIBUTE_NODE) {
  43136. this.name = payload.name;
  43137. this.value = payload.value;
  43138. }
  43139. }
  43140.  
  43141.  
  43142. WebInspector.DOMNode.XPathStep = function(value, optimized)
  43143. {
  43144. this.value = value;
  43145. this.optimized = optimized;
  43146. }
  43147.  
  43148. WebInspector.DOMNode.XPathStep.prototype = {
  43149. toString: function()
  43150. {
  43151. return this.value;
  43152. }
  43153. }
  43154.  
  43155. WebInspector.DOMNode.prototype = {
  43156.  
  43157. hasAttributes: function()
  43158. {
  43159. return this._attributes.length > 0;
  43160. },
  43161.  
  43162.  
  43163. hasChildNodes: function()
  43164. {
  43165. return this._childNodeCount > 0 || !!this._shadowRoots.length;
  43166. },
  43167.  
  43168.  
  43169. hasShadowRoots: function()
  43170. {
  43171. return !!this._shadowRoots.length;
  43172. },
  43173.  
  43174.  
  43175. nodeType: function()
  43176. {
  43177. return this._nodeType;
  43178. },
  43179.  
  43180.  
  43181. nodeName: function()
  43182. {
  43183. return this._nodeName;
  43184. },
  43185.  
  43186.  
  43187. isInShadowTree: function()
  43188. {
  43189. return this._isInShadowTree;
  43190. },
  43191.  
  43192.  
  43193. nodeNameInCorrectCase: function()
  43194. {
  43195. return this.isXMLNode() ? this.nodeName() : this.nodeName().toLowerCase();
  43196. },
  43197.  
  43198.  
  43199. setNodeName: function(name, callback)
  43200. {
  43201. DOMAgent.setNodeName(this.id, name, WebInspector.domAgent._markRevision(this, callback));
  43202. },
  43203.  
  43204.  
  43205. localName: function()
  43206. {
  43207. return this._localName;
  43208. },
  43209.  
  43210.  
  43211. nodeValue: function()
  43212. {
  43213. return this._nodeValue;
  43214. },
  43215.  
  43216.  
  43217. setNodeValue: function(value, callback)
  43218. {
  43219. DOMAgent.setNodeValue(this.id, value, WebInspector.domAgent._markRevision(this, callback));
  43220. },
  43221.  
  43222.  
  43223. getAttribute: function(name)
  43224. {
  43225. var attr = this._attributesMap[name];
  43226. return attr ? attr.value : undefined;
  43227. },
  43228.  
  43229.  
  43230. setAttribute: function(name, text, callback)
  43231. {
  43232. DOMAgent.setAttributesAsText(this.id, text, name, WebInspector.domAgent._markRevision(this, callback));
  43233. },
  43234.  
  43235.  
  43236. setAttributeValue: function(name, value, callback)
  43237. {
  43238. DOMAgent.setAttributeValue(this.id, name, value, WebInspector.domAgent._markRevision(this, callback));
  43239. },
  43240.  
  43241.  
  43242. attributes: function()
  43243. {
  43244. return this._attributes;
  43245. },
  43246.  
  43247.  
  43248. removeAttribute: function(name, callback)
  43249. {
  43250.  
  43251. function mycallback(error)
  43252. {
  43253. if (!error) {
  43254. delete this._attributesMap[name];
  43255. for (var i = 0;  i < this._attributes.length; ++i) {
  43256. if (this._attributes[i].name === name) {
  43257. this._attributes.splice(i, 1);
  43258. break;
  43259. }
  43260. }
  43261. }
  43262.  
  43263. WebInspector.domAgent._markRevision(this, callback)(error);
  43264. }
  43265. DOMAgent.removeAttribute(this.id, name, mycallback.bind(this));
  43266. },
  43267.  
  43268.  
  43269. getChildNodes: function(callback)
  43270. {
  43271. if (this.children) {
  43272. if (callback)
  43273. callback(this.children);
  43274. return;
  43275. }
  43276.  
  43277.  
  43278. function mycallback(error)
  43279. {
  43280. if (!error && callback)
  43281. callback(this.children);
  43282. }
  43283.  
  43284. DOMAgent.requestChildNodes(this.id, mycallback.bind(this));
  43285. },
  43286.  
  43287.  
  43288. getOuterHTML: function(callback)
  43289. {
  43290. DOMAgent.getOuterHTML(this.id, callback);
  43291. },
  43292.  
  43293.  
  43294. setOuterHTML: function(html, callback)
  43295. {
  43296. DOMAgent.setOuterHTML(this.id, html, WebInspector.domAgent._markRevision(this, callback));
  43297. },
  43298.  
  43299.  
  43300. removeNode: function(callback)
  43301. {
  43302. DOMAgent.removeNode(this.id, WebInspector.domAgent._markRevision(this, callback));
  43303. },
  43304.  
  43305. copyNode: function()
  43306. {
  43307. function copy(error, text)
  43308. {
  43309. if (!error)
  43310. InspectorFrontendHost.copyText(text);
  43311. }
  43312. DOMAgent.getOuterHTML(this.id, copy);
  43313. },
  43314.  
  43315.  
  43316. copyXPath: function(optimized)
  43317. {
  43318. InspectorFrontendHost.copyText(this.xPath(optimized));
  43319. },
  43320.  
  43321.  
  43322. eventListeners: function(callback)
  43323. {
  43324. DOMAgent.getEventListenersForNode(this.id, callback);
  43325. },
  43326.  
  43327.  
  43328. path: function()
  43329. {
  43330. var path = [];
  43331. var node = this;
  43332. while (node && "index" in node && node._nodeName.length) {
  43333. path.push([node.index, node._nodeName]);
  43334. node = node.parentNode;
  43335. }
  43336. path.reverse();
  43337. return path.join(",");
  43338. },
  43339.  
  43340.  
  43341. appropriateSelectorFor: function(justSelector)
  43342. {
  43343. var lowerCaseName = this.localName() || this.nodeName().toLowerCase();
  43344.  
  43345. var id = this.getAttribute("id");
  43346. if (id) {
  43347. var selector = "#" + id;
  43348. return (justSelector ? selector : lowerCaseName + selector);
  43349. }
  43350.  
  43351. var className = this.getAttribute("class");
  43352. if (className) {
  43353. var selector = "." + className.trim().replace(/\s+/g, ".");
  43354. return (justSelector ? selector : lowerCaseName + selector);
  43355. }
  43356.  
  43357. if (lowerCaseName === "input" && this.getAttribute("type"))
  43358. return lowerCaseName + "[type=\"" + this.getAttribute("type") + "\"]";
  43359.  
  43360. return lowerCaseName;
  43361. },
  43362.  
  43363.  
  43364. isAncestor: function(node)
  43365. {
  43366. if (!node)
  43367. return false;
  43368.  
  43369. var currentNode = node.parentNode;
  43370. while (currentNode) {
  43371. if (this === currentNode)
  43372. return true;
  43373. currentNode = currentNode.parentNode;
  43374. }
  43375. return false;
  43376. },
  43377.  
  43378.  
  43379. isDescendant: function(descendant)
  43380. {
  43381. return descendant !== null && descendant.isAncestor(this);
  43382. },
  43383.  
  43384.  
  43385. _setAttributesPayload: function(attrs)
  43386. {
  43387. var attributesChanged = !this._attributes || attrs.length !== this._attributes.length * 2;
  43388. var oldAttributesMap = this._attributesMap || {};
  43389.  
  43390. this._attributes = [];
  43391. this._attributesMap = {};
  43392.  
  43393. for (var i = 0; i < attrs.length; i += 2) {
  43394. var name = attrs[i];
  43395. var value = attrs[i + 1];
  43396. this._addAttribute(name, value);
  43397.  
  43398. if (attributesChanged)
  43399. continue;
  43400.  
  43401. if (!oldAttributesMap[name] || oldAttributesMap[name].value !== value)
  43402. attributesChanged = true;
  43403. }
  43404. return attributesChanged;
  43405. },
  43406.  
  43407.  
  43408. _insertChild: function(prev, payload)
  43409. {
  43410. var node = new WebInspector.DOMNode(this._domAgent, this.ownerDocument, this._isInShadowTree, payload);
  43411. if (!prev) {
  43412. if (!this.children) {
  43413.  
  43414. this.children = this._shadowRoots.concat([ node ]);
  43415. } else
  43416. this.children.unshift(node);
  43417. } else
  43418. this.children.splice(this.children.indexOf(prev) + 1, 0, node);
  43419. this._renumber();
  43420. return node;
  43421. },
  43422.  
  43423.  
  43424. _removeChild: function(node)
  43425. {
  43426. this.children.splice(this.children.indexOf(node), 1);
  43427. node.parentNode = null;
  43428. node._updateChildUserPropertyCountsOnRemoval(this);
  43429. this._renumber();
  43430. },
  43431.  
  43432.  
  43433. _setChildrenPayload: function(payloads)
  43434. {
  43435.  
  43436. if (this._contentDocument)
  43437. return;
  43438.  
  43439. this.children = this._shadowRoots.slice();
  43440. for (var i = 0; i < payloads.length; ++i) {
  43441. var payload = payloads[i];
  43442. var node = new WebInspector.DOMNode(this._domAgent, this.ownerDocument, this._isInShadowTree, payload);
  43443. this.children.push(node);
  43444. }
  43445. this._renumber();
  43446. },
  43447.  
  43448. _renumber: function()
  43449. {
  43450. this._childNodeCount = this.children.length;
  43451. if (this._childNodeCount == 0) {
  43452. this.firstChild = null;
  43453. this.lastChild = null;
  43454. return;
  43455. }
  43456. this.firstChild = this.children[0];
  43457. this.lastChild = this.children[this._childNodeCount - 1];
  43458. for (var i = 0; i < this._childNodeCount; ++i) {
  43459. var child = this.children[i];
  43460. child.index = i;
  43461. child.nextSibling = i + 1 < this._childNodeCount ? this.children[i + 1] : null;
  43462. child.previousSibling = i - 1 >= 0 ? this.children[i - 1] : null;
  43463. child.parentNode = this;
  43464. }
  43465. },
  43466.  
  43467.  
  43468. _addAttribute: function(name, value)
  43469. {
  43470. var attr = {
  43471. name: name,
  43472. value: value,
  43473. _node: this
  43474. };
  43475. this._attributesMap[name] = attr;
  43476. this._attributes.push(attr);
  43477. },
  43478.  
  43479.  
  43480. _setAttribute: function(name, value)
  43481. {
  43482. var attr = this._attributesMap[name];
  43483. if (attr)
  43484. attr.value = value;
  43485. else
  43486. this._addAttribute(name, value);
  43487. },
  43488.  
  43489.  
  43490. _removeAttribute: function(name)
  43491. {
  43492. var attr = this._attributesMap[name];
  43493. if (attr) {
  43494. this._attributes.remove(attr);
  43495. delete this._attributesMap[name];
  43496. }
  43497. },
  43498.  
  43499.  
  43500. moveTo: function(targetNode, anchorNode, callback)
  43501. {
  43502. DOMAgent.moveTo(this.id, targetNode.id, anchorNode ? anchorNode.id : undefined, WebInspector.domAgent._markRevision(this, callback));
  43503. },
  43504.  
  43505.  
  43506. isXMLNode: function()
  43507. {
  43508. return !!this.ownerDocument && !!this.ownerDocument.xmlVersion;
  43509. },
  43510.  
  43511.  
  43512. xPath: function(optimized)
  43513. {
  43514. if (this._nodeType === Node.DOCUMENT_NODE)
  43515. return "/";
  43516.  
  43517. var steps = [];
  43518. var contextNode = this;
  43519. while (contextNode) {
  43520. var step = contextNode._xPathValue(optimized);
  43521. if (!step)
  43522. break; 
  43523. steps.push(step);
  43524. if (step.optimized)
  43525. break;
  43526. contextNode = contextNode.parentNode;
  43527. }
  43528.  
  43529. steps.reverse();
  43530. return (steps.length && steps[0].optimized ? "" : "/") + steps.join("/");
  43531. },
  43532.  
  43533.  
  43534. _xPathValue: function(optimized)
  43535. {
  43536. var ownValue;
  43537. var ownIndex = this._xPathIndex();
  43538. if (ownIndex === -1)
  43539. return null; 
  43540.  
  43541. switch (this._nodeType) {
  43542. case Node.ELEMENT_NODE:
  43543. if (optimized && this.getAttribute("id"))
  43544. return new WebInspector.DOMNode.XPathStep("//*[@id=\"" + this.getAttribute("id") + "\"]", true);
  43545. ownValue = this._localName;
  43546. break;
  43547. case Node.ATTRIBUTE_NODE:
  43548. ownValue = "@" + this._nodeName;
  43549. break;
  43550. case Node.TEXT_NODE:
  43551. case Node.CDATA_SECTION_NODE:
  43552. ownValue = "text()";
  43553. break;
  43554. case Node.PROCESSING_INSTRUCTION_NODE:
  43555. ownValue = "processing-instruction()";
  43556. break;
  43557. case Node.COMMENT_NODE:
  43558. ownValue = "comment()";
  43559. break;
  43560. case Node.DOCUMENT_NODE:
  43561. ownValue = "";
  43562. break;
  43563. default:
  43564. ownValue = "";
  43565. break;
  43566. }
  43567.  
  43568. if (ownIndex > 0)
  43569. ownValue += "[" + ownIndex + "]";
  43570.  
  43571. return new WebInspector.DOMNode.XPathStep(ownValue, this._nodeType === Node.DOCUMENT_NODE);
  43572. },
  43573.  
  43574.  
  43575. _xPathIndex: function()
  43576. {
  43577.  
  43578. function areNodesSimilar(left, right)
  43579. {
  43580. if (left === right)
  43581. return true;
  43582.  
  43583. if (left._nodeType === Node.ELEMENT_NODE && right._nodeType === Node.ELEMENT_NODE)
  43584. return left._localName === right._localName;
  43585.  
  43586. if (left._nodeType === right._nodeType)
  43587. return true;
  43588.  
  43589.  
  43590. var leftType = left._nodeType === Node.CDATA_SECTION_NODE ? Node.TEXT_NODE : left._nodeType;
  43591. var rightType = right._nodeType === Node.CDATA_SECTION_NODE ? Node.TEXT_NODE : right._nodeType;
  43592. return leftType === rightType;
  43593. }
  43594.  
  43595. var siblings = this.parentNode ? this.parentNode.children : null;
  43596. if (!siblings)
  43597. return 0; 
  43598. var hasSameNamedElements;
  43599. for (var i = 0; i < siblings.length; ++i) {
  43600. if (areNodesSimilar(this, siblings[i]) && siblings[i] !== this) {
  43601. hasSameNamedElements = true;
  43602. break;
  43603. }
  43604. }
  43605. if (!hasSameNamedElements)
  43606. return 0;
  43607. var ownIndex = 1; 
  43608. for (var i = 0; i < siblings.length; ++i) {
  43609. if (areNodesSimilar(this, siblings[i])) {
  43610. if (siblings[i] === this)
  43611. return ownIndex;
  43612. ++ownIndex;
  43613. }
  43614. }
  43615. return -1; 
  43616. },
  43617.  
  43618. _updateChildUserPropertyCountsOnRemoval: function(parentNode)
  43619. {
  43620. var result = {};
  43621. if (this._userProperties) {
  43622. for (var name in this._userProperties)
  43623. result[name] = (result[name] || 0) + 1;
  43624. }
  43625.  
  43626. if (this._descendantUserPropertyCounters) {
  43627. for (var name in this._descendantUserPropertyCounters) {
  43628. var counter = this._descendantUserPropertyCounters[name];
  43629. result[name] = (result[name] || 0) + counter;
  43630. }
  43631. }
  43632.  
  43633. for (var name in result)
  43634. parentNode._updateDescendantUserPropertyCount(name, -result[name]);
  43635. },
  43636.  
  43637. _updateDescendantUserPropertyCount: function(name, delta)
  43638. {
  43639. if (!this._descendantUserPropertyCounters.hasOwnProperty(name))
  43640. this._descendantUserPropertyCounters[name] = 0;
  43641. this._descendantUserPropertyCounters[name] += delta;
  43642. if (!this._descendantUserPropertyCounters[name])
  43643. delete this._descendantUserPropertyCounters[name];
  43644. if (this.parentNode)
  43645. this.parentNode._updateDescendantUserPropertyCount(name, delta);
  43646. },
  43647.  
  43648. setUserProperty: function(name, value)
  43649. {
  43650. if (value === null) {
  43651. this.removeUserProperty(name);
  43652. return;
  43653. }
  43654.  
  43655. if (this.parentNode && !this._userProperties.hasOwnProperty(name))
  43656. this.parentNode._updateDescendantUserPropertyCount(name, 1);
  43657.  
  43658. this._userProperties[name] = value;
  43659. },
  43660.  
  43661. removeUserProperty: function(name)
  43662. {
  43663. if (!this._userProperties.hasOwnProperty(name))
  43664. return;
  43665.  
  43666. delete this._userProperties[name];
  43667. if (this.parentNode)
  43668. this.parentNode._updateDescendantUserPropertyCount(name, -1);
  43669. },
  43670.  
  43671. getUserProperty: function(name)
  43672. {
  43673. return this._userProperties ? this._userProperties[name] : null;
  43674. },
  43675.  
  43676. descendantUserPropertyCount: function(name)
  43677. {
  43678. return this._descendantUserPropertyCounters && this._descendantUserPropertyCounters[name] ? this._descendantUserPropertyCounters[name] : 0;
  43679. },
  43680.  
  43681.  
  43682. resolveURL: function(url)
  43683. {
  43684. if (!url)
  43685. return url;
  43686. for (var frameOwnerCandidate = this; frameOwnerCandidate; frameOwnerCandidate = frameOwnerCandidate.parentNode) {
  43687. if (frameOwnerCandidate.baseURL)
  43688. return WebInspector.ParsedURL.completeURL(frameOwnerCandidate.baseURL, url);
  43689. }
  43690. return null;
  43691. }
  43692. }
  43693.  
  43694.  
  43695. WebInspector.DOMDocument = function(domAgent, payload)
  43696. {
  43697. WebInspector.DOMNode.call(this, domAgent, this, false, payload);
  43698. this.documentURL = payload.documentURL || "";
  43699. this.baseURL =   (payload.baseURL);
  43700. console.assert(this.baseURL);
  43701. this.xmlVersion = payload.xmlVersion;
  43702. this._listeners = {};
  43703. }
  43704.  
  43705. WebInspector.DOMDocument.prototype = {
  43706. __proto__: WebInspector.DOMNode.prototype
  43707. }
  43708.  
  43709.  
  43710. WebInspector.DOMAgent = function() {
  43711.  
  43712. this._idToDOMNode = {};
  43713. this._document = null;
  43714. this._attributeLoadNodeIds = {};
  43715. InspectorBackend.registerDOMDispatcher(new WebInspector.DOMDispatcher(this));
  43716. if (WebInspector.settings.emulateTouchEvents.get())
  43717. this._emulateTouchEventsChanged();
  43718. WebInspector.settings.emulateTouchEvents.addChangeListener(this._emulateTouchEventsChanged, this);
  43719. }
  43720.  
  43721. WebInspector.DOMAgent.Events = {
  43722. AttrModified: "AttrModified",
  43723. AttrRemoved: "AttrRemoved",
  43724. CharacterDataModified: "CharacterDataModified",
  43725. NodeInserted: "NodeInserted",
  43726. NodeRemoved: "NodeRemoved",
  43727. DocumentUpdated: "DocumentUpdated",
  43728. ChildNodeCountUpdated: "ChildNodeCountUpdated",
  43729. InspectElementRequested: "InspectElementRequested",
  43730. UndoRedoRequested: "UndoRedoRequested",
  43731. UndoRedoCompleted: "UndoRedoCompleted"
  43732. }
  43733.  
  43734. WebInspector.DOMAgent.prototype = {
  43735.  
  43736. requestDocument: function(callback)
  43737. {
  43738. if (this._document) {
  43739. if (callback)
  43740. callback(this._document);
  43741. return;
  43742. }
  43743.  
  43744. if (this._pendingDocumentRequestCallbacks) {
  43745. this._pendingDocumentRequestCallbacks.push(callback);
  43746. return;
  43747. }
  43748.  
  43749. this._pendingDocumentRequestCallbacks = [callback];
  43750.  
  43751.  
  43752. function onDocumentAvailable(error, root)
  43753. {
  43754. if (!error)
  43755. this._setDocument(root);
  43756.  
  43757. for (var i = 0; i < this._pendingDocumentRequestCallbacks.length; ++i) {
  43758. var callback = this._pendingDocumentRequestCallbacks[i];
  43759. if (callback)
  43760. callback(this._document);
  43761. }
  43762. delete this._pendingDocumentRequestCallbacks;
  43763. }
  43764.  
  43765. DOMAgent.getDocument(onDocumentAvailable.bind(this));
  43766. },
  43767.  
  43768.  
  43769. existingDocument: function()
  43770. {
  43771. return this._document;
  43772. },
  43773.  
  43774.  
  43775. pushNodeToFrontend: function(objectId, callback)
  43776. {
  43777. var callbackCast =   callback;
  43778. this._dispatchWhenDocumentAvailable(DOMAgent.requestNode.bind(DOMAgent, objectId), callbackCast);
  43779. },
  43780.  
  43781.  
  43782. pushNodeByPathToFrontend: function(path, callback)
  43783. {
  43784. var callbackCast =   callback;
  43785. this._dispatchWhenDocumentAvailable(DOMAgent.pushNodeByPathToFrontend.bind(DOMAgent, path), callbackCast);
  43786. },
  43787.  
  43788.  
  43789. _wrapClientCallback: function(callback)
  43790. {
  43791. if (!callback)
  43792. return;
  43793.  
  43794. return function(error, result)
  43795. {
  43796.  
  43797. callback(error ? null : result);
  43798. }
  43799. },
  43800.  
  43801.  
  43802. _dispatchWhenDocumentAvailable: function(func, callback)
  43803. {
  43804. var callbackWrapper =   this._wrapClientCallback(callback);
  43805.  
  43806. function onDocumentAvailable()
  43807. {
  43808. if (this._document)
  43809. func(callbackWrapper);
  43810. else {
  43811. if (callbackWrapper)
  43812. callbackWrapper("No document");
  43813. }
  43814. }
  43815. this.requestDocument(onDocumentAvailable.bind(this));
  43816. },
  43817.  
  43818.  
  43819. _attributeModified: function(nodeId, name, value)
  43820. {
  43821. var node = this._idToDOMNode[nodeId];
  43822. if (!node)
  43823. return;
  43824.  
  43825. node._setAttribute(name, value);
  43826. this.dispatchEventToListeners(WebInspector.DOMAgent.Events.AttrModified, { node: node, name: name });
  43827. },
  43828.  
  43829.  
  43830. _attributeRemoved: function(nodeId, name)
  43831. {
  43832. var node = this._idToDOMNode[nodeId];
  43833. if (!node)
  43834. return;
  43835. node._removeAttribute(name);
  43836. this.dispatchEventToListeners(WebInspector.DOMAgent.Events.AttrRemoved, { node: node, name: name });
  43837. },
  43838.  
  43839.  
  43840. _inlineStyleInvalidated: function(nodeIds)
  43841. {
  43842. for (var i = 0; i < nodeIds.length; ++i)
  43843. this._attributeLoadNodeIds[nodeIds[i]] = true;
  43844. if ("_loadNodeAttributesTimeout" in this)
  43845. return;
  43846. this._loadNodeAttributesTimeout = setTimeout(this._loadNodeAttributes.bind(this), 0);
  43847. },
  43848.  
  43849. _loadNodeAttributes: function()
  43850. {
  43851.  
  43852. function callback(nodeId, error, attributes)
  43853. {
  43854. if (error) {
  43855.  
  43856. return;
  43857. }
  43858. var node = this._idToDOMNode[nodeId];
  43859. if (node) {
  43860. if (node._setAttributesPayload(attributes))
  43861. this.dispatchEventToListeners(WebInspector.DOMAgent.Events.AttrModified, { node: node, name: "style" });
  43862. }
  43863. }
  43864.  
  43865. delete this._loadNodeAttributesTimeout;
  43866.  
  43867. for (var nodeId in this._attributeLoadNodeIds) {
  43868. var nodeIdAsNumber = parseInt(nodeId, 10);
  43869. DOMAgent.getAttributes(nodeIdAsNumber, callback.bind(this, nodeIdAsNumber));
  43870. }
  43871. this._attributeLoadNodeIds = {};
  43872. },
  43873.  
  43874.  
  43875. _characterDataModified: function(nodeId, newValue)
  43876. {
  43877. var node = this._idToDOMNode[nodeId];
  43878. node._nodeValue = newValue;
  43879. this.dispatchEventToListeners(WebInspector.DOMAgent.Events.CharacterDataModified, node);
  43880. },
  43881.  
  43882.  
  43883. nodeForId: function(nodeId)
  43884. {
  43885. return this._idToDOMNode[nodeId];
  43886. },
  43887.  
  43888. _documentUpdated: function()
  43889. {
  43890. this._setDocument(null);
  43891. },
  43892.  
  43893.  
  43894. _setDocument: function(payload)
  43895. {
  43896. this._idToDOMNode = {};
  43897. if (payload && "nodeId" in payload)
  43898. this._document = new WebInspector.DOMDocument(this, payload);
  43899. else
  43900. this._document = null;
  43901. this.dispatchEventToListeners(WebInspector.DOMAgent.Events.DocumentUpdated, this._document);
  43902. },
  43903.  
  43904.  
  43905. _setDetachedRoot: function(payload)
  43906. {
  43907. if (payload.nodeName === "#document")
  43908. new WebInspector.DOMDocument(this, payload);
  43909. else
  43910. new WebInspector.DOMNode(this, null, false, payload);
  43911. },
  43912.  
  43913.  
  43914. _setChildNodes: function(parentId, payloads)
  43915. {
  43916. if (!parentId && payloads.length) {
  43917. this._setDetachedRoot(payloads[0]);
  43918. return;
  43919. }
  43920.  
  43921. var parent = this._idToDOMNode[parentId];
  43922. parent._setChildrenPayload(payloads);
  43923. },
  43924.  
  43925.  
  43926. _childNodeCountUpdated: function(nodeId, newValue)
  43927. {
  43928. var node = this._idToDOMNode[nodeId];
  43929. node._childNodeCount = newValue;
  43930. this.dispatchEventToListeners(WebInspector.DOMAgent.Events.ChildNodeCountUpdated, node);
  43931. },
  43932.  
  43933.  
  43934. _childNodeInserted: function(parentId, prevId, payload)
  43935. {
  43936. var parent = this._idToDOMNode[parentId];
  43937. var prev = this._idToDOMNode[prevId];
  43938. var node = parent._insertChild(prev, payload);
  43939. this._idToDOMNode[node.id] = node;
  43940. this.dispatchEventToListeners(WebInspector.DOMAgent.Events.NodeInserted, node);
  43941. },
  43942.  
  43943.  
  43944. _childNodeRemoved: function(parentId, nodeId)
  43945. {
  43946. var parent = this._idToDOMNode[parentId];
  43947. var node = this._idToDOMNode[nodeId];
  43948. parent._removeChild(node);
  43949. this._unbind(node);
  43950. this.dispatchEventToListeners(WebInspector.DOMAgent.Events.NodeRemoved, {node: node, parent: parent});
  43951. },
  43952.  
  43953.  
  43954. _shadowRootPopped: function(rootId)
  43955. {
  43956. },
  43957.  
  43958.  
  43959. _unbind: function(node)
  43960. {
  43961. delete this._idToDOMNode[node.id];
  43962. for (var i = 0; node.children && i < node.children.length; ++i)
  43963. this._unbind(node.children[i]);
  43964. },
  43965.  
  43966.  
  43967. inspectElement: function(nodeId)
  43968. {
  43969. var node = this._idToDOMNode[nodeId];
  43970. if (node)
  43971. this.dispatchEventToListeners(WebInspector.DOMAgent.Events.InspectElementRequested, node);
  43972. },
  43973.  
  43974.  
  43975. performSearch: function(query, searchCallback)
  43976. {
  43977. this.cancelSearch();
  43978.  
  43979.  
  43980. function callback(error, searchId, resultsCount)
  43981. {
  43982. this._searchId = searchId;
  43983. searchCallback(resultsCount);
  43984. }
  43985. DOMAgent.performSearch(query, callback.bind(this));
  43986. },
  43987.  
  43988.  
  43989. searchResult: function(index, callback)
  43990. {
  43991. if (this._searchId) {
  43992.  
  43993. function mycallback(error, nodeIds)
  43994. {
  43995. if (error) {
  43996. console.error(error);
  43997. callback(null);
  43998. return;
  43999. }
  44000. if (nodeIds.length != 1)
  44001. return;
  44002.  
  44003. callback(this._idToDOMNode[nodeIds[0]]);
  44004. }
  44005. DOMAgent.getSearchResults(this._searchId, index, index + 1, mycallback.bind(this));
  44006. } else
  44007. callback(null);
  44008. },
  44009.  
  44010. cancelSearch: function()
  44011. {
  44012. if (this._searchId) {
  44013. DOMAgent.discardSearchResults(this._searchId);
  44014. delete this._searchId;
  44015. }
  44016. },
  44017.  
  44018.  
  44019. querySelector: function(nodeId, selectors, callback)
  44020. {
  44021. var callbackCast =  callback;
  44022. DOMAgent.querySelector(nodeId, selectors, this._wrapClientCallback(callbackCast));
  44023. },
  44024.  
  44025.  
  44026. querySelectorAll: function(nodeId, selectors, callback)
  44027. {
  44028. var callbackCast =  callback;
  44029. DOMAgent.querySelectorAll(nodeId, selectors, this._wrapClientCallback(callbackCast));
  44030. },
  44031.  
  44032.  
  44033. highlightDOMNode: function(nodeId, mode, objectId)
  44034. {
  44035. if (this._hideDOMNodeHighlightTimeout) {
  44036. clearTimeout(this._hideDOMNodeHighlightTimeout);
  44037. delete this._hideDOMNodeHighlightTimeout;
  44038. }
  44039.  
  44040. if (objectId || nodeId)
  44041. DOMAgent.highlightNode(this._buildHighlightConfig(mode), objectId ? undefined : nodeId, objectId);
  44042. else
  44043. DOMAgent.hideHighlight();
  44044. },
  44045.  
  44046. hideDOMNodeHighlight: function()
  44047. {
  44048. this.highlightDOMNode(0);
  44049. },
  44050.  
  44051.  
  44052. highlightDOMNodeForTwoSeconds: function(nodeId)
  44053. {
  44054. this.highlightDOMNode(nodeId);
  44055. this._hideDOMNodeHighlightTimeout = setTimeout(this.hideDOMNodeHighlight.bind(this), 2000);
  44056. },
  44057.  
  44058.  
  44059. setInspectModeEnabled: function(enabled, callback)
  44060. {
  44061. DOMAgent.setInspectModeEnabled(enabled, this._buildHighlightConfig(), callback);
  44062. },
  44063.  
  44064.  
  44065. _buildHighlightConfig: function(mode)
  44066. {
  44067. mode = mode || "all";
  44068. var highlightConfig = { showInfo: mode === "all", showRulers: WebInspector.settings.showMetricsRulers.get() };
  44069. if (mode === "all" || mode === "content")
  44070. highlightConfig.contentColor = WebInspector.Color.PageHighlight.Content.toProtocolRGBA();
  44071.  
  44072. if (mode === "all" || mode === "padding")
  44073. highlightConfig.paddingColor = WebInspector.Color.PageHighlight.Padding.toProtocolRGBA();
  44074.  
  44075. if (mode === "all" || mode === "border")
  44076. highlightConfig.borderColor = WebInspector.Color.PageHighlight.Border.toProtocolRGBA();
  44077.  
  44078. if (mode === "all" || mode === "margin")
  44079. highlightConfig.marginColor = WebInspector.Color.PageHighlight.Margin.toProtocolRGBA();
  44080.  
  44081. return highlightConfig;
  44082. },
  44083.  
  44084.  
  44085. _markRevision: function(node, callback)
  44086. {
  44087. function wrapperFunction(error)
  44088. {
  44089. if (!error)
  44090. this.markUndoableState();
  44091.  
  44092. if (callback)
  44093. callback.apply(this, arguments);
  44094. }
  44095. return wrapperFunction.bind(this);
  44096. },
  44097.  
  44098. _emulateTouchEventsChanged: function()
  44099. {
  44100. const injectedFunction = function() {
  44101. const touchEvents = ["ontouchstart", "ontouchend", "ontouchmove", "ontouchcancel"];
  44102. var recepients = [window.__proto__, document.__proto__];
  44103. for (var i = 0; i < touchEvents.length; ++i) {
  44104. for (var j = 0; j < recepients.length; ++j) {
  44105. if (!(touchEvents[i] in recepients[j]))
  44106. Object.defineProperty(recepients[j], touchEvents[i], { value: null, writable: true, configurable: true, enumerable: true });
  44107. }
  44108. }
  44109. }
  44110.  
  44111. var emulationEnabled = WebInspector.settings.emulateTouchEvents.get();
  44112. if (emulationEnabled && !this._addTouchEventsScriptInjecting) {
  44113. this._addTouchEventsScriptInjecting = true;
  44114. PageAgent.addScriptToEvaluateOnLoad("(" + injectedFunction.toString() + ")", scriptAddedCallback.bind(this));
  44115. } else {
  44116. if (typeof this._addTouchEventsScriptId !== "undefined") {
  44117. PageAgent.removeScriptToEvaluateOnLoad(this._addTouchEventsScriptId);
  44118. delete this._addTouchEventsScriptId;
  44119. }
  44120. }
  44121.  
  44122. function scriptAddedCallback(error, scriptId)
  44123. {
  44124. delete this._addTouchEventsScriptInjecting;
  44125. if (error)
  44126. return;
  44127. this._addTouchEventsScriptId = scriptId;
  44128. }
  44129.  
  44130. PageAgent.setTouchEmulationEnabled(emulationEnabled);
  44131. },
  44132.  
  44133. markUndoableState: function()
  44134. {
  44135. DOMAgent.markUndoableState();
  44136. },
  44137.  
  44138.  
  44139. undo: function(callback)
  44140. {
  44141. function mycallback(error)
  44142. {
  44143. this.dispatchEventToListeners(WebInspector.DOMAgent.Events.UndoRedoCompleted);
  44144. callback(error);
  44145. }
  44146.  
  44147. this.dispatchEventToListeners(WebInspector.DOMAgent.Events.UndoRedoRequested);
  44148. DOMAgent.undo(callback);
  44149. },
  44150.  
  44151.  
  44152. redo: function(callback)
  44153. {
  44154. function mycallback(error)
  44155. {
  44156. this.dispatchEventToListeners(WebInspector.DOMAgent.Events.UndoRedoCompleted);
  44157. callback(error);
  44158. }
  44159.  
  44160. this.dispatchEventToListeners(WebInspector.DOMAgent.Events.UndoRedoRequested);
  44161. DOMAgent.redo(callback);
  44162. },
  44163.  
  44164. __proto__: WebInspector.Object.prototype
  44165. }
  44166.  
  44167.  
  44168. WebInspector.DOMDispatcher = function(domAgent)
  44169. {
  44170. this._domAgent = domAgent;
  44171. }
  44172.  
  44173. WebInspector.DOMDispatcher.prototype = {
  44174. documentUpdated: function()
  44175. {
  44176. this._domAgent._documentUpdated();
  44177. },
  44178.  
  44179.  
  44180. attributeModified: function(nodeId, name, value)
  44181. {
  44182. this._domAgent._attributeModified(nodeId, name, value);
  44183. },
  44184.  
  44185.  
  44186. attributeRemoved: function(nodeId, name)
  44187. {
  44188. this._domAgent._attributeRemoved(nodeId, name);
  44189. },
  44190.  
  44191.  
  44192. inlineStyleInvalidated: function(nodeIds)
  44193. {
  44194. this._domAgent._inlineStyleInvalidated(nodeIds);
  44195. },
  44196.  
  44197.  
  44198. characterDataModified: function(nodeId, characterData)
  44199. {
  44200. this._domAgent._characterDataModified(nodeId, characterData);
  44201. },
  44202.  
  44203.  
  44204. setChildNodes: function(parentId, payloads)
  44205. {
  44206. this._domAgent._setChildNodes(parentId, payloads);
  44207. },
  44208.  
  44209.  
  44210. childNodeCountUpdated: function(nodeId, childNodeCount)
  44211. {
  44212. this._domAgent._childNodeCountUpdated(nodeId, childNodeCount);
  44213. },
  44214.  
  44215.  
  44216. childNodeInserted: function(parentNodeId, previousNodeId, payload)
  44217. {
  44218. this._domAgent._childNodeInserted(parentNodeId, previousNodeId, payload);
  44219. },
  44220.  
  44221.  
  44222. childNodeRemoved: function(parentNodeId, nodeId)
  44223. {
  44224. this._domAgent._childNodeRemoved(parentNodeId, nodeId);
  44225. },
  44226.  
  44227.  
  44228. shadowRootPushed: function(hostId, root)
  44229. {
  44230. this._domAgent._childNodeInserted(hostId, 0, root);
  44231. },
  44232.  
  44233.  
  44234. shadowRootPopped: function(hostId, rootId)
  44235. {
  44236. this._domAgent._childNodeRemoved(hostId, rootId);
  44237. }
  44238. }
  44239.  
  44240.  
  44241. WebInspector.domAgent = null;
  44242.  
  44243.  
  44244.  
  44245.  
  44246.  
  44247. WebInspector.evaluateForTestInFrontend = function(callId, script)
  44248. {
  44249. if (!InspectorFrontendHost.isUnderTest())
  44250. return;
  44251.  
  44252. function invokeMethod()
  44253. {
  44254. var message;
  44255. try {
  44256. script = script + "//@ sourceURL=evaluateInWebInspector" + callId + ".js";
  44257. var result = window.eval(script);
  44258. message = typeof result === "undefined" ? "\"<undefined>\"" : JSON.stringify(result);
  44259. } catch (e) {
  44260. message = e.toString();
  44261. }
  44262. RuntimeAgent.evaluate("didEvaluateForTestInFrontend(" + callId + ", " + message + ")", "test");
  44263. }
  44264. InspectorBackend.runAfterPendingDispatches(invokeMethod);
  44265. }
  44266.  
  44267.  
  44268.  
  44269.  
  44270.  
  44271.  
  44272. WebInspector.Dialog = function(relativeToElement, delegate)
  44273. {
  44274. this._delegate = delegate;
  44275. this._relativeToElement = relativeToElement;
  44276.  
  44277.  
  44278. this._glassPaneElement = document.body.createChild("div");
  44279. this._glassPaneElement.className = "dialog-glass-pane";
  44280. this._glassPaneElement.tabIndex = 0;
  44281. this._glassPaneElement.addEventListener("focus", this._onGlassPaneFocus.bind(this), false);
  44282.  
  44283. this._element = this._glassPaneElement.createChild("div");
  44284. this._element.tabIndex = 0;
  44285. this._element.addEventListener("focus", this._onFocus.bind(this), false);
  44286. this._element.addEventListener("keydown", this._onKeyDown.bind(this), false);
  44287. this._closeKeys = [
  44288. WebInspector.KeyboardShortcut.Keys.Enter.code,
  44289. WebInspector.KeyboardShortcut.Keys.Esc.code,
  44290. ];
  44291.  
  44292. delegate.show(this._element);
  44293.  
  44294. this._position();
  44295. this._windowResizeHandler = this._position.bind(this);
  44296. window.addEventListener("resize", this._windowResizeHandler, true);
  44297.  
  44298. this._previousFocusElement = WebInspector.currentFocusElement();
  44299. this._delegate.focus();
  44300. }
  44301.  
  44302.  
  44303. WebInspector.Dialog.currentInstance = function()
  44304. {
  44305. return WebInspector.Dialog._instance;
  44306. }
  44307.  
  44308.  
  44309. WebInspector.Dialog.show = function(relativeToElement, delegate)
  44310. {
  44311. if (WebInspector.Dialog._instance)
  44312. return;
  44313. WebInspector.Dialog._instance = new WebInspector.Dialog(relativeToElement, delegate);
  44314. }
  44315.  
  44316. WebInspector.Dialog.hide = function()
  44317. {
  44318. if (!WebInspector.Dialog._instance)
  44319. return;
  44320. WebInspector.Dialog._instance._hide();
  44321. }
  44322.  
  44323. WebInspector.Dialog.prototype = {
  44324. _hide: function()
  44325. {
  44326. if (this._isHiding)
  44327. return;
  44328. this._isHiding = true;
  44329.  
  44330. this._delegate.willHide();
  44331.  
  44332. if (this._element.isSelfOrAncestor(document.activeElement))
  44333. WebInspector.setCurrentFocusElement(this._previousFocusElement);
  44334. delete WebInspector.Dialog._instance;
  44335. document.body.removeChild(this._glassPaneElement);
  44336. window.removeEventListener("resize", this._windowResizeHandler, true);
  44337. },
  44338.  
  44339. _onGlassPaneFocus: function(event)
  44340. {
  44341. this._hide();
  44342. },
  44343.  
  44344. _onFocus: function(event)
  44345. {
  44346. this._delegate.focus();
  44347. },
  44348.  
  44349. _position: function()
  44350. {
  44351. this._delegate.position(this._element, this._relativeToElement);
  44352. },
  44353.  
  44354. _onKeyDown: function(event)
  44355. {
  44356. if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Tab.code) {
  44357. event.preventDefault();
  44358. return;
  44359. }
  44360.  
  44361. if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Enter.code)
  44362. this._delegate.onEnter();
  44363.  
  44364. if (this._closeKeys.indexOf(event.keyCode) >= 0) {
  44365. this._hide();
  44366. event.consume(true);
  44367. }
  44368. }
  44369. };
  44370.  
  44371.  
  44372. WebInspector.DialogDelegate = function()
  44373. {
  44374. }
  44375.  
  44376. WebInspector.DialogDelegate.prototype = {
  44377.  
  44378. show: function(element)
  44379. {
  44380. element.appendChild(this.element);
  44381. this.element.addStyleClass("dialog-contents");
  44382. element.addStyleClass("dialog");    
  44383. },
  44384.  
  44385.  
  44386. position: function(element, relativeToElement)
  44387. {
  44388. var offset = relativeToElement.offsetRelativeToWindow(window);
  44389.  
  44390. var positionX = offset.x + (relativeToElement.offsetWidth - element.offsetWidth) / 2;
  44391. positionX = Number.constrain(positionX, 0, window.innerWidth - element.offsetWidth);
  44392.  
  44393. var positionY = offset.y + (relativeToElement.offsetHeight - element.offsetHeight) / 2;
  44394. positionY = Number.constrain(positionY, 0, window.innerHeight - element.offsetHeight);
  44395.  
  44396. element.style.left = positionX + "px";
  44397. element.style.top = positionY + "px";
  44398. },
  44399.  
  44400. focus: function() { },
  44401.  
  44402. onEnter: function() { },
  44403.  
  44404. willHide: function() { },
  44405.  
  44406. __proto__: WebInspector.Object.prototype
  44407. }
  44408.  
  44409.  
  44410.  
  44411.  
  44412.  
  44413.  
  44414.  
  44415. WebInspector.GoToLineDialog = function(view)
  44416. {
  44417. WebInspector.DialogDelegate.call(this);
  44418.  
  44419. this.element = document.createElement("div");
  44420. this.element.className = "go-to-line-dialog";
  44421.  
  44422. this.element.createChild("label").textContent = WebInspector.UIString("Go to line: ");
  44423.  
  44424. this._input = this.element.createChild("input");
  44425. this._input.setAttribute("type", "text");
  44426. this._input.setAttribute("size", 6);
  44427.  
  44428. this._goButton = this.element.createChild("button");
  44429. this._goButton.textContent = WebInspector.UIString("Go");
  44430. this._goButton.addEventListener("click", this._onGoClick.bind(this), false);
  44431.  
  44432. this._view = view;
  44433. }
  44434.  
  44435.  
  44436. WebInspector.GoToLineDialog.install = function(panel, viewGetter)
  44437. {
  44438. function showGoToLineDialog()
  44439. {
  44440. var view = viewGetter();
  44441. if (view)
  44442. WebInspector.GoToLineDialog._show(view);
  44443. }
  44444.  
  44445. var goToLineShortcut = WebInspector.GoToLineDialog.createShortcut();
  44446. panel.registerShortcuts([goToLineShortcut], showGoToLineDialog);
  44447. }
  44448.  
  44449. WebInspector.GoToLineDialog._show = function(sourceView)
  44450. {
  44451. if (!sourceView || !sourceView.canHighlightLine())
  44452. return;
  44453. WebInspector.Dialog.show(sourceView.element, new WebInspector.GoToLineDialog(sourceView));
  44454. }
  44455.  
  44456.  
  44457. WebInspector.GoToLineDialog.createShortcut = function()
  44458. {
  44459. var isMac = WebInspector.isMac();
  44460. var shortcut;
  44461. if (isMac)
  44462. return WebInspector.KeyboardShortcut.makeDescriptor("l", WebInspector.KeyboardShortcut.Modifiers.Meta);
  44463. return WebInspector.KeyboardShortcut.makeDescriptor("g", WebInspector.KeyboardShortcut.Modifiers.Ctrl);
  44464. }
  44465.  
  44466. WebInspector.GoToLineDialog.prototype = {
  44467. focus: function()
  44468. {
  44469. WebInspector.setCurrentFocusElement(this._input);
  44470. this._input.select();
  44471. },
  44472.  
  44473. _onGoClick: function()
  44474. {
  44475. this._applyLineNumber();
  44476. WebInspector.Dialog.hide();
  44477. },
  44478.  
  44479. _applyLineNumber: function()
  44480. {
  44481. var value = this._input.value;
  44482. var lineNumber = parseInt(value, 10) - 1;
  44483. if (!isNaN(lineNumber) && lineNumber >= 0)
  44484. this._view.highlightLine(lineNumber);
  44485. },
  44486.  
  44487. onEnter: function()
  44488. {
  44489. this._applyLineNumber();
  44490. },
  44491.  
  44492. __proto__: WebInspector.DialogDelegate.prototype
  44493. }
  44494.  
  44495.  
  44496.  
  44497.  
  44498.  
  44499.  
  44500. WebInspector.SidebarOverlay = function(view, widthSettingName, minimalWidth)
  44501. {
  44502. this.element = document.createElement("div");
  44503. this.element.className = "sidebar-overlay";
  44504.  
  44505. this._view = view;
  44506. this._widthSettingName = widthSettingName;
  44507. this._minimalWidth = minimalWidth;
  44508. this._savedWidth = minimalWidth || 300;
  44509.  
  44510. if (this._widthSettingName)
  44511. WebInspector.settings[this._widthSettingName] = WebInspector.settings.createSetting(this._widthSettingName, undefined);
  44512.  
  44513. this._resizerElement = document.createElement("div");
  44514. this._resizerElement.className = "sidebar-overlay-resizer";
  44515. this._installResizer(this._resizerElement);
  44516. }
  44517.  
  44518. WebInspector.SidebarOverlay.prototype = {
  44519.  
  44520. show: function(relativeToElement)
  44521. {
  44522. relativeToElement.appendChild(this.element);
  44523. relativeToElement.addStyleClass("sidebar-overlay-shown");
  44524. this._view.show(this.element);
  44525. this.element.appendChild(this._resizerElement);
  44526. if (this._resizerWidgetElement)
  44527. this.element.appendChild(this._resizerWidgetElement);
  44528. this.position(relativeToElement);
  44529. },
  44530.  
  44531.  
  44532. position: function(relativeToElement)
  44533. {
  44534. this._totalWidth = relativeToElement.offsetWidth;
  44535. this._setWidth(this._preferredWidth());
  44536. },
  44537.  
  44538. focus: function()
  44539. {
  44540. WebInspector.setCurrentFocusElement(this._view.element);
  44541. },
  44542.  
  44543. hide: function()
  44544. {
  44545. var element = this.element.parentElement;
  44546. if (!element)
  44547. return;
  44548.  
  44549. this._view.detach();
  44550. element.removeChild(this.element);
  44551. element.removeStyleClass("sidebar-overlay-shown");
  44552. this.element.removeChild(this._resizerElement);
  44553. if (this._resizerWidgetElement)
  44554. this.element.removeChild(this._resizerWidgetElement);
  44555. },
  44556.  
  44557.  
  44558. _setWidth: function(newWidth)
  44559. {
  44560. var width = Number.constrain(newWidth, this._minimalWidth, this._totalWidth);
  44561.  
  44562. if (this._width === width)
  44563. return;
  44564.  
  44565. this.element.style.width = width + "px";
  44566. this._resizerElement.style.left = (width - 3) + "px";
  44567. this._width = width;
  44568. this._view.doResize();
  44569. this._saveWidth();
  44570. },
  44571.  
  44572.  
  44573. _preferredWidth: function()
  44574. {
  44575. if (!this._widthSettingName)
  44576. return this._savedWidth;
  44577.  
  44578. return WebInspector.settings[this._widthSettingName].get() || this._savedWidth;
  44579. },
  44580.  
  44581. _saveWidth: function()
  44582. {
  44583. this._savedWidth = this._width;
  44584. if (!this._widthSettingName)
  44585. return;
  44586.  
  44587. WebInspector.settings[this._widthSettingName].set(this._width);
  44588. },
  44589.  
  44590.  
  44591. _startResizerDragging: function(event)
  44592. {
  44593. var width = this._width;
  44594. this._dragOffset = width - event.pageX;
  44595. return true;
  44596. },
  44597.  
  44598.  
  44599. _resizerDragging: function(event)
  44600. {
  44601. var width = event.pageX + this._dragOffset;
  44602. this._setWidth(width);
  44603. event.preventDefault();
  44604. },
  44605.  
  44606.  
  44607. _endResizerDragging: function(event)
  44608. {
  44609. delete this._dragOffset;
  44610. },
  44611.  
  44612.  
  44613. _installResizer: function(resizerElement)
  44614. {
  44615. WebInspector.installDragHandle(resizerElement, this._startResizerDragging.bind(this), this._resizerDragging.bind(this), this._endResizerDragging.bind(this), "ew-resize");
  44616. },
  44617.  
  44618.  
  44619. set resizerWidgetElement(resizerWidgetElement)
  44620. {
  44621. this._resizerWidgetElement = resizerWidgetElement;
  44622. this._installResizer(resizerWidgetElement);
  44623. }
  44624. }
  44625.  
  44626.  
  44627.  
  44628.  
  44629.  
  44630.  
  44631. WebInspector.SettingsScreen = function(onHide)
  44632. {
  44633. WebInspector.HelpScreen.call(this);
  44634. this.element.id = "settings-screen";
  44635.  
  44636.  
  44637. this._onHide = onHide;
  44638.  
  44639. this._tabbedPane = new WebInspector.TabbedPane();
  44640. this._tabbedPane.element.addStyleClass("help-window-main");
  44641. var settingsLabelElement = document.createElement("div");
  44642. settingsLabelElement.className = "help-window-label";
  44643. settingsLabelElement.createTextChild(WebInspector.UIString("Settings"));
  44644. this._tabbedPane.element.insertBefore(settingsLabelElement, this._tabbedPane.element.firstChild);
  44645. this._tabbedPane.element.appendChild(this._createCloseButton());
  44646. this._tabbedPane.appendTab(WebInspector.SettingsScreen.Tabs.General, WebInspector.UIString("General"), new WebInspector.GenericSettingsTab());
  44647. if (!WebInspector.experimentsSettings.showOverridesInDrawer.isEnabled())
  44648. this._tabbedPane.appendTab(WebInspector.SettingsScreen.Tabs.Overrides, WebInspector.UIString("Overrides"), new WebInspector.OverridesSettingsTab());
  44649. if (WebInspector.experimentsSettings.experimentsEnabled)
  44650. this._tabbedPane.appendTab(WebInspector.SettingsScreen.Tabs.Experiments, WebInspector.UIString("Experiments"), new WebInspector.ExperimentsSettingsTab());
  44651. this._tabbedPane.appendTab(WebInspector.SettingsScreen.Tabs.Shortcuts, WebInspector.UIString("Shortcuts"), WebInspector.shortcutsScreen.createShortcutsTabView());
  44652. this._tabbedPane.shrinkableTabs = false;
  44653. this._tabbedPane.verticalTabLayout = true;
  44654.  
  44655. this._lastSelectedTabSetting = WebInspector.settings.createSetting("lastSelectedSettingsTab", WebInspector.SettingsScreen.Tabs.General);
  44656. this.selectTab(this._lastSelectedTabSetting.get());
  44657. this._tabbedPane.addEventListener(WebInspector.TabbedPane.EventTypes.TabSelected, this._tabSelected, this);
  44658. }
  44659.  
  44660. WebInspector.SettingsScreen.Tabs = {
  44661. General: "general",
  44662. Overrides: "overrides",
  44663. Experiments: "experiments",
  44664. Shortcuts: "shortcuts"
  44665. }
  44666.  
  44667. WebInspector.SettingsScreen.prototype = {
  44668.  
  44669. selectTab: function(tabId)
  44670. {
  44671. this._tabbedPane.selectTab(tabId);
  44672. },
  44673.  
  44674.  
  44675. _tabSelected: function(event)
  44676. {
  44677. this._lastSelectedTabSetting.set(this._tabbedPane.selectedTabId);
  44678. },
  44679.  
  44680.  
  44681. wasShown: function()
  44682. {
  44683. this._tabbedPane.show(this.element);
  44684. WebInspector.HelpScreen.prototype.wasShown.call(this);
  44685. },
  44686.  
  44687.  
  44688. isClosingKey: function(keyCode)
  44689. {
  44690. return [
  44691. WebInspector.KeyboardShortcut.Keys.Enter.code,
  44692. WebInspector.KeyboardShortcut.Keys.Esc.code,
  44693. ].indexOf(keyCode) >= 0;
  44694. },
  44695.  
  44696.  
  44697. willHide: function()
  44698. {
  44699. this._onHide();
  44700. WebInspector.HelpScreen.prototype.willHide.call(this);
  44701. },
  44702.  
  44703. __proto__: WebInspector.HelpScreen.prototype
  44704. }
  44705.  
  44706.  
  44707. WebInspector.SettingsTab = function(name, id)
  44708. {
  44709. WebInspector.View.call(this);
  44710. this.element.className = "settings-tab-container";
  44711. if (id)
  44712. this.element.id = id;
  44713. var header = this.element.createChild("header");
  44714. header.createChild("h3").appendChild(document.createTextNode(name));
  44715. this.containerElement = this.element.createChild("div", "help-container-wrapper").createChild("div", "settings-tab help-content help-container");
  44716. }
  44717.  
  44718. WebInspector.SettingsTab.prototype = {
  44719.  
  44720. _appendSection: function(name)
  44721. {
  44722. var block = this.containerElement.createChild("div", "help-block");
  44723. if (name)
  44724. block.createChild("div", "help-section-title").textContent = name;
  44725. return block;
  44726. },
  44727.  
  44728.  
  44729. _createCheckboxSetting: function(name, setting, omitParagraphElement, inputElement)
  44730. {
  44731. var input = inputElement || document.createElement("input");
  44732. input.type = "checkbox";
  44733. input.name = name;
  44734. input.checked = setting.get();
  44735.  
  44736. function listener()
  44737. {
  44738. setting.set(input.checked);
  44739. }
  44740. input.addEventListener("click", listener, false);
  44741.  
  44742. var label = document.createElement("label");
  44743. label.appendChild(input);
  44744. label.appendChild(document.createTextNode(name));
  44745. if (omitParagraphElement)
  44746. return label;
  44747.  
  44748. var p = document.createElement("p");
  44749. p.appendChild(label);
  44750. return p;
  44751. },
  44752.  
  44753. _createSelectSetting: function(name, options, setting)
  44754. {
  44755. var fieldsetElement = document.createElement("fieldset");
  44756. fieldsetElement.createChild("label").textContent = name;
  44757.  
  44758. var select = document.createElement("select");
  44759. var settingValue = setting.get();
  44760.  
  44761. for (var i = 0; i < options.length; ++i) {
  44762. var option = options[i];
  44763. select.add(new Option(option[0], option[1]));
  44764. if (settingValue === option[1])
  44765. select.selectedIndex = i;
  44766. }
  44767.  
  44768. function changeListener(e)
  44769. {
  44770. setting.set(e.target.value);
  44771. }
  44772.  
  44773. select.addEventListener("change", changeListener, false);
  44774. fieldsetElement.appendChild(select);
  44775.  
  44776. var p = document.createElement("p");
  44777. p.appendChild(fieldsetElement);
  44778. return p;
  44779. },
  44780.  
  44781. _createRadioSetting: function(name, options, setting)
  44782. {
  44783. var pp = document.createElement("p");
  44784. var fieldsetElement = document.createElement("fieldset");
  44785. var legendElement = document.createElement("legend");
  44786. legendElement.textContent = name;
  44787. fieldsetElement.appendChild(legendElement);
  44788.  
  44789. function clickListener(e)
  44790. {
  44791. setting.set(e.target.value);
  44792. }
  44793.  
  44794. var settingValue = setting.get();
  44795. for (var i = 0; i < options.length; ++i) {
  44796. var p = document.createElement("p");
  44797. var label = document.createElement("label");
  44798. p.appendChild(label);
  44799.  
  44800. var input = document.createElement("input");
  44801. input.type = "radio";
  44802. input.name = setting.name;
  44803. input.value = options[i][0];
  44804. input.addEventListener("click", clickListener, false);
  44805. if (settingValue == input.value)
  44806. input.checked = true;
  44807.  
  44808. label.appendChild(input);
  44809. label.appendChild(document.createTextNode(options[i][1]));
  44810.  
  44811. fieldsetElement.appendChild(p);
  44812. }
  44813.  
  44814. pp.appendChild(fieldsetElement);
  44815. return pp;
  44816. },
  44817.  
  44818. _createCustomSetting: function(name, element)
  44819. {
  44820. var p = document.createElement("p");
  44821. var fieldsetElement = document.createElement("fieldset");
  44822. fieldsetElement.createChild("label").textContent = name;
  44823. fieldsetElement.appendChild(element);
  44824. p.appendChild(fieldsetElement);
  44825. return p;
  44826. },
  44827.  
  44828. __proto__: WebInspector.View.prototype
  44829. }
  44830.  
  44831.  
  44832. WebInspector.GenericSettingsTab = function()
  44833. {
  44834. WebInspector.SettingsTab.call(this, WebInspector.UIString("General"));
  44835.  
  44836. var p = this._appendSection();
  44837. if (Preferences.exposeDisableCache)
  44838. p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Disable cache"), WebInspector.settings.cacheDisabled));
  44839. var disableJSElement = this._createCheckboxSetting(WebInspector.UIString("Disable JavaScript"), WebInspector.settings.javaScriptDisabled);
  44840. p.appendChild(disableJSElement);
  44841. WebInspector.settings.javaScriptDisabled.addChangeListener(this._javaScriptDisabledChanged, this);
  44842. this._disableJSCheckbox = disableJSElement.getElementsByTagName("input")[0];
  44843. this._updateScriptDisabledCheckbox();
  44844.  
  44845. p = this._appendSection(WebInspector.UIString("Appearance"));
  44846. p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Show toolbar icons"), WebInspector.settings.showToolbarIcons));
  44847.  
  44848. p = this._appendSection(WebInspector.UIString("Elements"));
  44849. p.appendChild(this._createRadioSetting(WebInspector.UIString("Color format"), [
  44850. [ WebInspector.Color.Format.Original, WebInspector.UIString("As authored") ],
  44851. [ WebInspector.Color.Format.HEX, "HEX: #DAC0DE" ],
  44852. [ WebInspector.Color.Format.RGB, "RGB: rgb(128, 255, 255)" ],
  44853. [ WebInspector.Color.Format.HSL, "HSL: hsl(300, 80%, 90%)" ] ], WebInspector.settings.colorFormat));
  44854. p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Show user agent styles"), WebInspector.settings.showUserAgentStyles));
  44855. p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Word wrap"), WebInspector.settings.domWordWrap));
  44856. p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Show Shadow DOM"), WebInspector.settings.showShadowDOM));
  44857. p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Show rulers"), WebInspector.settings.showMetricsRulers));
  44858.  
  44859. p = this._appendSection(WebInspector.UIString("Rendering"));
  44860. p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Show paint rectangles"), WebInspector.settings.showPaintRects));
  44861. WebInspector.settings.showPaintRects.addChangeListener(this._showPaintRectsChanged, this);
  44862.  
  44863. if (Capabilities.canShowFPSCounter) {
  44864. p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Show FPS meter"), WebInspector.settings.showFPSCounter));
  44865. WebInspector.settings.showFPSCounter.addChangeListener(this._showFPSCounterChanged, this);
  44866. }
  44867.  
  44868. p = this._appendSection(WebInspector.UIString("Sources"));
  44869. p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Show folders"), WebInspector.settings.showScriptFolders));
  44870. p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Search in content scripts"), WebInspector.settings.searchInContentScripts));
  44871. p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Enable source maps"), WebInspector.settings.sourceMapsEnabled));
  44872. if (WebInspector.experimentsSettings.isEnabled("sass"))
  44873. p.appendChild(this._createCSSAutoReloadControls());
  44874. var indentationElement = this._createSelectSetting(WebInspector.UIString("Indentation"), [
  44875. [ WebInspector.UIString("2 spaces"), WebInspector.TextEditorModel.Indent.TwoSpaces ],
  44876. [ WebInspector.UIString("4 spaces"), WebInspector.TextEditorModel.Indent.FourSpaces ],
  44877. [ WebInspector.UIString("8 spaces"), WebInspector.TextEditorModel.Indent.EightSpaces ],
  44878. [ WebInspector.UIString("Tab character"), WebInspector.TextEditorModel.Indent.TabCharacter ]
  44879. ], WebInspector.settings.textEditorIndent);
  44880. indentationElement.firstChild.className = "toplevel";
  44881. p.appendChild(indentationElement);
  44882.  
  44883. p = this._appendSection(WebInspector.UIString("Profiler"));
  44884. p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Show objects' hidden properties"), WebInspector.settings.showHeapSnapshotObjectsHiddenProperties));
  44885. if (WebInspector.experimentsSettings.nativeMemorySnapshots.isEnabled())
  44886. p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Show uninstrumented native memory"), WebInspector.settings.showNativeSnapshotUninstrumentedSize));
  44887.  
  44888. if (Capabilities.timelineCanMonitorMainThread) {
  44889. p = this._appendSection(WebInspector.UIString("Timeline"));
  44890. p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Show CPU activity on the ruler"), WebInspector.settings.showCpuOnTimelineRuler));
  44891. }
  44892.  
  44893. p = this._appendSection(WebInspector.UIString("Console"));
  44894. p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Log XMLHttpRequests"), WebInspector.settings.monitoringXHREnabled));
  44895. p.appendChild(this._createCheckboxSetting(WebInspector.UIString("Preserve log upon navigation"), WebInspector.settings.preserveConsoleLog));
  44896.  
  44897. if (WebInspector.extensionServer.hasExtensions()) {
  44898. var handlerSelector = new WebInspector.HandlerSelector(WebInspector.openAnchorLocationRegistry);
  44899. p = this._appendSection(WebInspector.UIString("Extensions"));
  44900. p.appendChild(this._createCustomSetting(WebInspector.UIString("Open links in"), handlerSelector.element));
  44901. }
  44902. }
  44903.  
  44904. WebInspector.GenericSettingsTab.prototype = {
  44905. _showPaintRectsChanged: function()
  44906. {
  44907. PageAgent.setShowPaintRects(WebInspector.settings.showPaintRects.get());
  44908. },
  44909.  
  44910. _showFPSCounterChanged: function()
  44911. {
  44912. PageAgent.setShowFPSCounter(WebInspector.settings.showFPSCounter.get());
  44913. },
  44914.  
  44915. _updateScriptDisabledCheckbox: function()
  44916. {
  44917. function executionStatusCallback(error, status)
  44918. {
  44919. if (error || !status)
  44920. return;
  44921.  
  44922. switch (status) {
  44923. case "forbidden":
  44924. this._disableJSCheckbox.checked = true;
  44925. this._disableJSCheckbox.disabled = true;
  44926. break;
  44927. case "disabled":
  44928. this._disableJSCheckbox.checked = true;
  44929. break;
  44930. default:
  44931. this._disableJSCheckbox.checked = false;
  44932. break;
  44933. }
  44934. }
  44935.  
  44936. PageAgent.getScriptExecutionStatus(executionStatusCallback.bind(this));
  44937. },
  44938.  
  44939. _javaScriptDisabledChanged: function()
  44940. {
  44941.  
  44942. PageAgent.setScriptExecutionDisabled(WebInspector.settings.javaScriptDisabled.get(), this._updateScriptDisabledCheckbox.bind(this));
  44943. },
  44944.  
  44945. _createCSSAutoReloadControls: function()
  44946. {
  44947. var fragment = document.createDocumentFragment();
  44948. var labelElement = fragment.createChild("label");
  44949. var checkboxElement = labelElement.createChild("input");
  44950. checkboxElement.type = "checkbox";
  44951. checkboxElement.checked = WebInspector.settings.cssReloadEnabled.get();
  44952. checkboxElement.addEventListener("click", checkboxClicked, false);
  44953. labelElement.appendChild(document.createTextNode(WebInspector.UIString("Auto-reload CSS upon Sass save")));
  44954.  
  44955. var fieldsetElement = fragment.createChild("fieldset");
  44956. fieldsetElement.disabled = !checkboxElement.checked;
  44957. var p = fieldsetElement.createChild("p");
  44958. p.appendChild(document.createTextNode(WebInspector.UIString("Timeout (ms)")));
  44959. p.appendChild(document.createTextNode(" "));
  44960. var timeoutInput = p.createChild("input");
  44961. timeoutInput.value = WebInspector.settings.cssReloadTimeout.get();
  44962. timeoutInput.className = "numeric";
  44963. timeoutInput.style.width = "60px";
  44964. timeoutInput.maxLength = 8;
  44965. timeoutInput.addEventListener("blur", blurListener, false);
  44966. return fragment;
  44967.  
  44968. function checkboxClicked()
  44969. {
  44970. var reloadEnabled = checkboxElement.checked;
  44971. WebInspector.settings.cssReloadEnabled.set(reloadEnabled);
  44972. fieldsetElement.disabled = !reloadEnabled;
  44973. }
  44974.  
  44975. function blurListener()
  44976. {
  44977. var value = timeoutInput.value;
  44978. if (!isFinite(value) || value <= 0) {
  44979. timeoutInput.value = WebInspector.settings.cssReloadTimeout.get();
  44980. return;
  44981. }
  44982. WebInspector.settings.cssReloadTimeout.set(Number(value));
  44983. }
  44984. },
  44985.  
  44986. __proto__: WebInspector.SettingsTab.prototype
  44987. }
  44988.  
  44989.  
  44990. WebInspector.OverridesSettingsTab = function()
  44991. {
  44992. WebInspector.SettingsTab.call(this, WebInspector.UIString("Overrides"), "overrides-tab-content");
  44993. this._view = new WebInspector.OverridesView();
  44994. this.containerElement.parentElement.appendChild(this._view.containerElement);
  44995. this.containerElement.remove();
  44996. this.containerElement = this._view.containerElement;
  44997. }
  44998.  
  44999. WebInspector.OverridesSettingsTab.prototype = {
  45000. __proto__: WebInspector.SettingsTab.prototype
  45001. }
  45002.  
  45003.  
  45004. WebInspector.ExperimentsSettingsTab = function()
  45005. {
  45006. WebInspector.SettingsTab.call(this, WebInspector.UIString("Experiments"), "experiments-tab-content");
  45007.  
  45008. var experiments = WebInspector.experimentsSettings.experiments;
  45009. if (experiments.length) {
  45010. var experimentsSection = this._appendSection();
  45011. experimentsSection.appendChild(this._createExperimentsWarningSubsection());
  45012. for (var i = 0; i < experiments.length; ++i)
  45013. experimentsSection.appendChild(this._createExperimentCheckbox(experiments[i]));
  45014. }
  45015. }
  45016.  
  45017. WebInspector.ExperimentsSettingsTab.prototype = {
  45018.  
  45019. _createExperimentsWarningSubsection: function()
  45020. {
  45021. var subsection = document.createElement("div");
  45022. var warning = subsection.createChild("span", "settings-experiments-warning-subsection-warning");
  45023. warning.textContent = WebInspector.UIString("WARNING:");
  45024. subsection.appendChild(document.createTextNode(" "));
  45025. var message = subsection.createChild("span", "settings-experiments-warning-subsection-message");
  45026. message.textContent = WebInspector.UIString("These experiments could be dangerous and may require restart.");
  45027. return subsection;
  45028. },
  45029.  
  45030. _createExperimentCheckbox: function(experiment)
  45031. {
  45032. var input = document.createElement("input");
  45033. input.type = "checkbox";
  45034. input.name = experiment.name;
  45035. input.checked = experiment.isEnabled();
  45036. function listener()
  45037. {
  45038. experiment.setEnabled(input.checked);
  45039. }
  45040. input.addEventListener("click", listener, false);
  45041.  
  45042. var p = document.createElement("p");
  45043. var label = document.createElement("label");
  45044. label.appendChild(input);
  45045. label.appendChild(document.createTextNode(WebInspector.UIString(experiment.title)));
  45046. p.appendChild(label);
  45047. return p;
  45048. },
  45049.  
  45050. __proto__: WebInspector.SettingsTab.prototype
  45051. }
  45052.  
  45053.  
  45054. WebInspector.SettingsController = function()
  45055. {
  45056. this._statusBarButton = new WebInspector.StatusBarButton(WebInspector.UIString("Settings"), "settings-status-bar-item");
  45057. if (WebInspector.experimentsSettings.showOverridesInDrawer.isEnabled())
  45058. this._statusBarButton.element.addEventListener("mousedown", this._mouseDown.bind(this), false);
  45059. else
  45060. this._statusBarButton.element.addEventListener("mouseup", this._mouseUp.bind(this), false);
  45061.  
  45062.  
  45063. this._settingsScreen;
  45064. }
  45065.  
  45066. WebInspector.SettingsController.prototype =
  45067. {
  45068. get statusBarItem()
  45069. {
  45070. return this._statusBarButton.element;
  45071. },
  45072.  
  45073.  
  45074. _mouseDown: function(event)
  45075. {
  45076. var contextMenu = new WebInspector.ContextMenu(event);
  45077. contextMenu.appendItem(WebInspector.UIString("Overrides"), showOverrides.bind(this));
  45078. contextMenu.appendItem(WebInspector.UIString("Settings"), showSettings.bind(this));
  45079.  
  45080. function showOverrides()
  45081. {
  45082. if (this._settingsScreenVisible)
  45083. this._hideSettingsScreen();
  45084. WebInspector.OverridesView.showInDrawer();
  45085. }
  45086.  
  45087. function showSettings()
  45088. {
  45089. if (!this._settingsScreenVisible)
  45090. this.showSettingsScreen();
  45091. }
  45092.  
  45093. contextMenu.showSoftMenu();
  45094. },
  45095.  
  45096.  
  45097. _mouseUp: function(event)
  45098. {
  45099. this.showSettingsScreen();
  45100. },
  45101.  
  45102. _onHideSettingsScreen: function()
  45103. {
  45104. delete this._settingsScreenVisible;
  45105. },
  45106.  
  45107.  
  45108. showSettingsScreen: function(tabId)
  45109. {
  45110. if (!this._settingsScreen)
  45111. this._settingsScreen = new WebInspector.SettingsScreen(this._onHideSettingsScreen.bind(this));
  45112.  
  45113. if (tabId)
  45114. this._settingsScreen.selectTab(tabId);
  45115.  
  45116. this._settingsScreen.showModal();
  45117. this._settingsScreenVisible = true;
  45118. },
  45119.  
  45120. _hideSettingsScreen: function()
  45121. {
  45122. if (this._settingsScreen)
  45123. this._settingsScreen.hide();
  45124. },
  45125.  
  45126. resize: function()
  45127. {
  45128. if (this._settingsScreen && this._settingsScreen.isShowing())
  45129. this._settingsScreen.doResize();
  45130. }
  45131. }
  45132.  
  45133.  
  45134.  
  45135.  
  45136.  
  45137.  
  45138. WebInspector.ShortcutsScreen = function()
  45139. {
  45140. this._sections =   ({});
  45141. }
  45142.  
  45143. WebInspector.ShortcutsScreen.prototype = {
  45144.  
  45145. section: function(name)
  45146. {
  45147. var section = this._sections[name];
  45148. if (!section)
  45149. this._sections[name] = section = new WebInspector.ShortcutsSection(name);
  45150. return section;
  45151. },
  45152.  
  45153.  
  45154. createShortcutsTabView: function()
  45155. {
  45156. var orderedSections = [];
  45157. for (var section in this._sections)
  45158. orderedSections.push(this._sections[section]);
  45159. function compareSections(a, b)
  45160. {
  45161. return a.order - b.order;
  45162. }
  45163. orderedSections.sort(compareSections);
  45164.  
  45165. var view = new WebInspector.View();
  45166.  
  45167. view.element.className = "settings-tab-container";
  45168. view.element.createChild("header").createChild("h3").appendChild(document.createTextNode(WebInspector.UIString("Shortcuts")));
  45169. var container = view.element.createChild("div", "help-container-wrapper").createChild("div");
  45170. container.className = "help-content help-container";
  45171. for (var i = 0; i < orderedSections.length; ++i)
  45172. orderedSections[i].renderSection(container);
  45173.  
  45174. return view;
  45175. }
  45176. }
  45177.  
  45178.  
  45179. WebInspector.shortcutsScreen = null;
  45180.  
  45181.  
  45182. WebInspector.ShortcutsSection = function(name)
  45183. {
  45184. this.name = name;
  45185. this._lines =   ([]);
  45186. this.order = ++WebInspector.ShortcutsSection._sequenceNumber;
  45187. };
  45188.  
  45189. WebInspector.ShortcutsSection._sequenceNumber = 0;
  45190.  
  45191. WebInspector.ShortcutsSection.prototype = {
  45192.  
  45193. addKey: function(key, description)
  45194. {
  45195. this._addLine(this._renderKey(key), description);
  45196. },
  45197.  
  45198.  
  45199. addRelatedKeys: function(keys, description)
  45200. {
  45201. this._addLine(this._renderSequence(keys, "/"), description);
  45202. },
  45203.  
  45204.  
  45205. addAlternateKeys: function(keys, description)
  45206. {
  45207. this._addLine(this._renderSequence(keys, WebInspector.UIString("or")), description);
  45208. },
  45209.  
  45210.  
  45211. _addLine: function(keyElement, description)
  45212. {
  45213. this._lines.push({ key: keyElement, text: description })
  45214. },
  45215.  
  45216.  
  45217. renderSection: function(container)
  45218. {
  45219. var parent = container.createChild("div", "help-block");
  45220.  
  45221. var headLine = parent.createChild("div", "help-line");
  45222. headLine.createChild("div", "help-key-cell");
  45223. headLine.createChild("div", "help-section-title help-cell").textContent = this.name;
  45224.  
  45225. for (var i = 0; i < this._lines.length; ++i) {
  45226. var line = parent.createChild("div", "help-line");
  45227. var keyCell = line.createChild("div", "help-key-cell");
  45228. keyCell.appendChild(this._lines[i].key);
  45229. keyCell.appendChild(this._createSpan("help-key-delimiter", ":"));
  45230. line.createChild("div", "help-cell").textContent = this._lines[i].text;
  45231. }
  45232. },
  45233.  
  45234.  
  45235. _renderSequence: function(sequence, delimiter)
  45236. {
  45237. var delimiterSpan = this._createSpan("help-key-delimiter", delimiter);
  45238. return this._joinNodes(sequence.map(this._renderKey.bind(this)), delimiterSpan);
  45239. },
  45240.  
  45241.  
  45242. _renderKey: function(key)
  45243. {
  45244. var keyName = key.name;
  45245. var plus = this._createSpan("help-combine-keys", "+");
  45246. return this._joinNodes(keyName.split(" + ").map(this._createSpan.bind(this, "help-key monospace")), plus);
  45247. },
  45248.  
  45249.  
  45250. _createSpan: function(className, textContent)
  45251. {
  45252. var node = document.createElement("span");
  45253. node.className = className;
  45254. node.textContent = textContent;
  45255. return node;
  45256. },
  45257.  
  45258.  
  45259. _joinNodes: function(nodes, delimiter)
  45260. {
  45261. var result = document.createDocumentFragment();
  45262. for (var i = 0; i < nodes.length; ++i) {
  45263. if (i > 0)
  45264. result.appendChild(delimiter.cloneNode(true));
  45265. result.appendChild(nodes[i]);
  45266. }
  45267. return result;
  45268. }
  45269. }
  45270.  
  45271.  
  45272.  
  45273.  
  45274.  
  45275.  
  45276. WebInspector.OverridesView = function()
  45277. {
  45278. WebInspector.View.call(this);
  45279. this.registerRequiredCSS("helpScreen.css");
  45280. this.element.addStyleClass("fill");
  45281. this.element.addStyleClass("help-window-main");
  45282. this.element.addStyleClass("settings-tab-container");
  45283.  
  45284. var paneContent = this.element.createChild("div", "tabbed-pane-content");
  45285.  
  45286. function appendBlockTo(targetElement, contentElement)
  45287. {
  45288. var blockElement = targetElement.createChild("div", "help-block");
  45289. blockElement.appendChild(contentElement);
  45290. }
  45291.  
  45292. var headerTitle = paneContent.createChild("header").createChild("h3");
  45293. headerTitle.appendChild(document.createTextNode(WebInspector.UIString("Overrides")));
  45294.  
  45295. var container = paneContent.createChild("div", "help-container-wrapper").createChild("div", "settings-tab help-content help-container");
  45296. this.containerElement = container;
  45297. appendBlockTo(container, this._createUserAgentControl());
  45298. if (Capabilities.canOverrideDeviceMetrics)
  45299. appendBlockTo(container, this._createDeviceMetricsControl());
  45300. if (Capabilities.canOverrideGeolocation)
  45301. appendBlockTo(container, this._createGeolocationOverrideControl());
  45302. if (Capabilities.canOverrideDeviceOrientation)
  45303. appendBlockTo(container, this._createDeviceOrientationOverrideControl());
  45304. appendBlockTo(container, this._createCheckboxSetting(WebInspector.UIString("Emulate touch events"), WebInspector.settings.emulateTouchEvents));
  45305. appendBlockTo(container, this._createMediaEmulationElement());
  45306.  
  45307. this._statusElement = document.createElement("span");
  45308. this._statusElement.textContent = WebInspector.UIString("Overrides");
  45309. }
  45310.  
  45311. WebInspector.OverridesView.showInDrawer = function()
  45312. {
  45313. if (!WebInspector.OverridesView._view)
  45314. WebInspector.OverridesView._view = new WebInspector.OverridesView();
  45315. var view = WebInspector.OverridesView._view;
  45316. WebInspector.showViewInDrawer(view._statusElement, view);
  45317. }
  45318.  
  45319. WebInspector.OverridesView.prototype = {
  45320.  
  45321. _createCheckboxSetting: function(name, setting, omitParagraphElement, inputElement)
  45322. {
  45323. var input = inputElement || document.createElement("input");
  45324. input.type = "checkbox";
  45325. input.name = name;
  45326. input.checked = setting.get();
  45327.  
  45328. function listener()
  45329. {
  45330. setting.set(input.checked);
  45331. }
  45332. input.addEventListener("click", listener, false);
  45333.  
  45334. var label = document.createElement("label");
  45335. label.appendChild(input);
  45336. label.appendChild(document.createTextNode(name));
  45337. if (omitParagraphElement)
  45338. return label;
  45339.  
  45340. var p = document.createElement("p");
  45341. p.appendChild(label);
  45342. return p;
  45343. },
  45344.  
  45345. _createUserAgentControl: function()
  45346. {
  45347. var userAgent = WebInspector.settings.userAgent.get();
  45348.  
  45349. var p = document.createElement("p");
  45350. var labelElement = p.createChild("label");
  45351. var checkboxElement = labelElement.createChild("input");
  45352. checkboxElement.type = "checkbox";
  45353. checkboxElement.checked = false;
  45354. labelElement.appendChild(document.createTextNode(WebInspector.UIString("User Agent")));
  45355. p.appendChild(this._createUserAgentSelectRowElement(checkboxElement));
  45356. return p;
  45357. },
  45358.  
  45359. _createUserAgentSelectRowElement: function(checkboxElement)
  45360. {
  45361. var userAgent = WebInspector.settings.userAgent.get();
  45362.  
  45363.  
  45364.  
  45365.  
  45366.  
  45367. const userAgents = [
  45368. ["Internet Explorer 9", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)"],
  45369. ["Internet Explorer 8", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)"],
  45370. ["Internet Explorer 7", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)"],
  45371.  
  45372. ["Firefox 7 \u2014 Windows", "Mozilla/5.0 (Windows NT 6.1; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"],
  45373. ["Firefox 7 \u2014 Mac", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"],
  45374. ["Firefox 4 \u2014 Windows", "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"],
  45375. ["Firefox 4 \u2014 Mac", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"],
  45376. ["Firefox 14 \u2014 Android Mobile", "Mozilla/5.0 (Android; Mobile; rv:14.0) Gecko/14.0 Firefox/14.0"],
  45377. ["Firefox 14 \u2014 Android Tablet", "Mozilla/5.0 (Android; Tablet; rv:14.0) Gecko/14.0 Firefox/14.0"],
  45378.  
  45379. ["Chrome \u2014 Android Mobile", "Mozilla/5.0 (Linux; Android 4.0.4; Galaxy Nexus Build/IMM76B) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.133 Mobile Safari/535.19"],
  45380. ["Chrome \u2014 Android Tablet", "Mozilla/5.0 (Linux; Android 4.1.2; Nexus 7 Build/JZ054K) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19"],
  45381.  
  45382. ["iPhone \u2014 iOS 5", "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3", "640x960x1"],
  45383. ["iPhone \u2014 iOS 4", "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5", "640x960x1"],
  45384. ["iPad \u2014 iOS 5", "Mozilla/5.0 (iPad; CPU OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3", "1024x768x1"],
  45385. ["iPad \u2014 iOS 4", "Mozilla/5.0 (iPad; CPU OS 4_3_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8H7 Safari/6533.18.5", "1024x768x1"],
  45386.  
  45387. ["Android 2.3 \u2014 Nexus S", "Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; Nexus S Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1", "480x800x1.1"],
  45388. ["Android 4.0.2 \u2014 Galaxy Nexus", "Mozilla/5.0 (Linux; U; Android 4.0.2; en-us; Galaxy Nexus Build/ICL53F) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30", "720x1280x1.1"],
  45389.  
  45390. ["BlackBerry \u2014 PlayBook 2.1", "Mozilla/5.0 (PlayBook; U; RIM Tablet OS 2.1.0; en-US) AppleWebKit/536.2+ (KHTML, like Gecko) Version/7.2.1.0 Safari/536.2+", "1024x600x1"],
  45391. ["BlackBerry \u2014 9900", "Mozilla/5.0 (BlackBerry; U; BlackBerry 9900; en-US) AppleWebKit/534.11+ (KHTML, like Gecko) Version/7.0.0.187 Mobile Safari/534.11+", "640x480x1"],
  45392. ["BlackBerry \u2014 BB10", "Mozilla/5.0 (BB10; Touch) AppleWebKit/537.1+ (KHTML, like Gecko) Version/10.0.0.1337 Mobile Safari/537.1+", "768x1280x1"],
  45393.  
  45394. ["MeeGo \u2014 Nokia N9", "Mozilla/5.0 (MeeGo; NokiaN9) AppleWebKit/534.13 (KHTML, like Gecko) NokiaBrowser/8.5.0 Mobile Safari/534.13", "480x854x1"],
  45395.  
  45396. [WebInspector.UIString("Other..."), "Other"]
  45397. ];
  45398.  
  45399. var fieldsetElement = document.createElement("fieldset");
  45400. this._selectElement = fieldsetElement.createChild("select");
  45401. this._otherUserAgentElement = fieldsetElement.createChild("input");
  45402. this._otherUserAgentElement.type = "text";
  45403. this._otherUserAgentElement.value = userAgent;
  45404. this._otherUserAgentElement.title = userAgent;
  45405. this._userAgentFieldsetElement = fieldsetElement;
  45406.  
  45407. var selectionRestored = false;
  45408. for (var i = 0; i < userAgents.length; ++i) {
  45409. var agent = userAgents[i];
  45410. var option = new Option(agent[0], agent[1]);
  45411. option._metrics = agent[2] ? agent[2] : "";
  45412. this._selectElement.add(option);
  45413. if (userAgent === agent[1]) {
  45414. this._selectElement.selectedIndex = i;
  45415. selectionRestored = true;
  45416. }
  45417. }
  45418.  
  45419. if (!selectionRestored) {
  45420. if (!userAgent)
  45421. this._selectElement.selectedIndex = 0;
  45422. else
  45423. this._selectElement.selectedIndex = userAgents.length - 1;
  45424. }
  45425.  
  45426. this._selectElement.addEventListener("change", this._selectionChanged.bind(this, true), false);
  45427.  
  45428. fieldsetElement.addEventListener("dblclick", textDoubleClicked.bind(this), false);
  45429. this._otherUserAgentElement.addEventListener("blur", textChanged.bind(this), false);
  45430.  
  45431. function textDoubleClicked()
  45432. {
  45433. this._selectElement.selectedIndex = userAgents.length - 1;
  45434. this._selectionChanged();
  45435. }
  45436.  
  45437. function textChanged()
  45438. {
  45439. WebInspector.settings.userAgent.set(this._otherUserAgentElement.value);
  45440. }
  45441.  
  45442. function checkboxClicked()
  45443. {
  45444. if (checkboxElement.checked) {
  45445. this._userAgentFieldsetElement.disabled = false;
  45446. this._selectionChanged();
  45447. } else {
  45448. this._userAgentFieldsetElement.disabled = true;
  45449. this._otherUserAgentElement.disabled = true;
  45450. }
  45451. WebInspector.userAgentSupport.toggleUserAgentOverride(checkboxElement.checked);
  45452. }
  45453. checkboxElement.addEventListener("click", checkboxClicked.bind(this), false);
  45454.  
  45455. checkboxClicked.call(this);
  45456. return fieldsetElement;
  45457. },
  45458.  
  45459.  
  45460. _selectionChanged: function(isUserGesture)
  45461. {
  45462. var value = this._selectElement.options[this._selectElement.selectedIndex].value;
  45463. if (value !== "Other") {
  45464. WebInspector.settings.userAgent.set(value);
  45465. this._otherUserAgentElement.value = value;
  45466. this._otherUserAgentElement.title = value;
  45467. this._otherUserAgentElement.disabled = true;
  45468. } else {
  45469. this._otherUserAgentElement.disabled = false;
  45470. this._otherUserAgentElement.focus();
  45471. }
  45472.  
  45473. if (isUserGesture && Capabilities.canOverrideDeviceMetrics) {
  45474. var metrics = this._selectElement.options[this._selectElement.selectedIndex]._metrics;
  45475. this._setDeviceMetricsOverride(WebInspector.UserAgentSupport.DeviceMetrics.parseSetting(metrics), false, true);
  45476. }
  45477. },
  45478.  
  45479.  
  45480. _createInput: function(parentElement, id, defaultText, eventListener, numeric)
  45481. {
  45482. var element = parentElement.createChild("input");
  45483. element.id = id;
  45484. element.type = "text";
  45485. element.maxLength = 12;
  45486. element.style.width = "80px";
  45487. element.value = defaultText;
  45488. element.align = "right";
  45489. if (numeric)
  45490. element.className = "numeric";
  45491. element.addEventListener("blur", eventListener, false);
  45492. return element;
  45493. },
  45494.  
  45495. _createDeviceMetricsControl: function()
  45496. {
  45497. const metricsSetting = WebInspector.settings.deviceMetrics.get();
  45498. var metrics = WebInspector.UserAgentSupport.DeviceMetrics.parseSetting(metricsSetting);
  45499.  
  45500. const p = document.createElement("p");
  45501. const labelElement = p.createChild("label");
  45502. const checkboxElement = labelElement.createChild("input");
  45503. checkboxElement.id = "metrics-override-checkbox";
  45504. checkboxElement.type = "checkbox";
  45505. checkboxElement.checked = false;
  45506. checkboxElement.addEventListener("click", this._onMetricsCheckboxClicked.bind(this), false);
  45507. this._metricsCheckboxElement = checkboxElement;
  45508. labelElement.appendChild(document.createTextNode(WebInspector.UIString("Device metrics")));
  45509.  
  45510. const metricsSectionElement = this._createDeviceMetricsElement(metrics);
  45511. p.appendChild(metricsSectionElement);
  45512. this._metricsSectionElement = metricsSectionElement;
  45513. this._onMetricsCheckboxClicked();
  45514.  
  45515. return p;
  45516. },
  45517.  
  45518. _onMetricsCheckboxClicked: function()
  45519. {
  45520. var controlsDisabled = !this._metricsCheckboxElement.checked;
  45521. this._deviceMetricsFieldsetElement.disabled = controlsDisabled;
  45522.  
  45523. if (controlsDisabled) {
  45524. WebInspector.userAgentSupport.toggleDeviceMetricsOverride(false);
  45525. return;
  45526. }
  45527.  
  45528. var metrics = WebInspector.UserAgentSupport.DeviceMetrics.parseUserInput(this._widthOverrideElement.value, this._heightOverrideElement.value, this._fontScaleFactorOverrideElement.value);
  45529. if (metrics && metrics.isValid() && metrics.width && metrics.height) {
  45530. this._setDeviceMetricsOverride(metrics, false, false);
  45531. WebInspector.userAgentSupport.toggleDeviceMetricsOverride(true);
  45532. }
  45533. if (!this._widthOverrideElement.value)
  45534. this._widthOverrideElement.focus();
  45535. },
  45536.  
  45537. _applyDeviceMetricsUserInput: function()
  45538. {
  45539. this._setDeviceMetricsOverride(WebInspector.UserAgentSupport.DeviceMetrics.parseUserInput(this._widthOverrideElement.value.trim(), this._heightOverrideElement.value.trim(), this._fontScaleFactorOverrideElement.value.trim()), true, false);
  45540. },
  45541.  
  45542.  
  45543. _setDeviceMetricsOverride: function(metrics, userInputModified, updateCheckbox)
  45544. {
  45545. function setValid(condition, element)
  45546. {
  45547. if (condition)
  45548. element.removeStyleClass("error-input");
  45549. else
  45550. element.addStyleClass("error-input");
  45551. }
  45552.  
  45553. setValid(metrics && metrics.isWidthValid(), this._widthOverrideElement);
  45554. setValid(metrics && metrics.isHeightValid(), this._heightOverrideElement);
  45555. setValid(metrics && metrics.isFontScaleFactorValid(), this._fontScaleFactorOverrideElement);
  45556.  
  45557. if (!metrics)
  45558. return;
  45559.  
  45560. if (!userInputModified) {
  45561. this._widthOverrideElement.value = metrics.widthToInput();
  45562. this._heightOverrideElement.value = metrics.heightToInput();
  45563. this._fontScaleFactorOverrideElement.value = metrics.fontScaleFactorToInput();
  45564. }
  45565.  
  45566. if (metrics.isValid()) {
  45567. var value = metrics.toSetting();
  45568. if (value !== WebInspector.settings.deviceMetrics.get())
  45569. WebInspector.settings.deviceMetrics.set(value);
  45570. }
  45571.  
  45572. if (this._metricsCheckboxElement && updateCheckbox) {
  45573. this._metricsCheckboxElement.checked = !!metrics.toSetting();
  45574. this._onMetricsCheckboxClicked();
  45575. }
  45576. },
  45577.  
  45578.  
  45579. _createDeviceMetricsElement: function(metrics)
  45580. {
  45581. var fieldsetElement = document.createElement("fieldset");
  45582. fieldsetElement.id = "metrics-override-section";
  45583. this._deviceMetricsFieldsetElement = fieldsetElement;
  45584.  
  45585. function swapDimensionsClicked(event)
  45586. {
  45587. var widthValue = this._widthOverrideElement.value;
  45588. this._widthOverrideElement.value = this._heightOverrideElement.value;
  45589. this._heightOverrideElement.value = widthValue;
  45590. this._applyDeviceMetricsUserInput();
  45591. }
  45592.  
  45593. var tableElement = fieldsetElement.createChild("table", "nowrap");
  45594.  
  45595. var rowElement = tableElement.createChild("tr");
  45596. var cellElement = rowElement.createChild("td");
  45597. cellElement.appendChild(document.createTextNode(WebInspector.UIString("Screen resolution:")));
  45598. cellElement = rowElement.createChild("td");
  45599. this._widthOverrideElement = this._createInput(cellElement, "metrics-override-width", String(metrics.width || screen.width), this._applyDeviceMetricsUserInput.bind(this), true);
  45600. cellElement.appendChild(document.createTextNode(" \u00D7 ")); 
  45601. this._heightOverrideElement = this._createInput(cellElement, "metrics-override-height", String(metrics.height || screen.height), this._applyDeviceMetricsUserInput.bind(this), true);
  45602. cellElement.appendChild(document.createTextNode(" \u2014 ")); 
  45603. this._swapDimensionsElement = cellElement.createChild("button");
  45604. this._swapDimensionsElement.appendChild(document.createTextNode(" \u21C4 ")); 
  45605. this._swapDimensionsElement.title = WebInspector.UIString("Swap dimensions");
  45606. this._swapDimensionsElement.addEventListener("click", swapDimensionsClicked.bind(this), false);
  45607.  
  45608. rowElement = tableElement.createChild("tr");
  45609. cellElement = rowElement.createChild("td");
  45610. cellElement.appendChild(document.createTextNode(WebInspector.UIString("Font scale factor:")));
  45611. cellElement = rowElement.createChild("td");
  45612. this._fontScaleFactorOverrideElement = this._createInput(cellElement, "metrics-override-font-scale", String(metrics.fontScaleFactor || 1), this._applyDeviceMetricsUserInput.bind(this), true);
  45613.  
  45614. rowElement = tableElement.createChild("tr");
  45615. cellElement = rowElement.createChild("td");
  45616. cellElement.colSpan = 2;
  45617. this._fitWindowCheckboxElement = document.createElement("input");
  45618. cellElement.appendChild(this._createCheckboxSetting(WebInspector.UIString("Fit in window"), WebInspector.settings.deviceFitWindow, true, this._fitWindowCheckboxElement));
  45619.  
  45620. return fieldsetElement;
  45621. },
  45622.  
  45623. _createGeolocationOverrideControl: function()
  45624. {
  45625. const geolocationSetting = WebInspector.settings.geolocationOverride.get();
  45626. var geolocation = WebInspector.UserAgentSupport.GeolocationPosition.parseSetting(geolocationSetting);
  45627. var p = document.createElement("p");
  45628. var labelElement = p.createChild("label");
  45629. var checkboxElement = labelElement.createChild("input");
  45630. checkboxElement.id = "geolocation-override-checkbox";
  45631. checkboxElement.type = "checkbox";
  45632. checkboxElement.checked = false;
  45633. checkboxElement.addEventListener("click", this._onGeolocationOverrideCheckboxClicked.bind(this), false);
  45634. this._geolocationOverrideCheckboxElement = checkboxElement;
  45635. labelElement.appendChild(document.createTextNode(WebInspector.UIString("Override Geolocation")));
  45636.  
  45637. var geolocationSectionElement = this._createGeolocationOverrideElement(geolocation);
  45638. p.appendChild(geolocationSectionElement);
  45639. this._geolocationSectionElement = geolocationSectionElement;
  45640. this._onGeolocationOverrideCheckboxClicked();
  45641. return p;
  45642. },
  45643.  
  45644. _onGeolocationOverrideCheckboxClicked: function()
  45645. {
  45646. var controlsDisabled = !this._geolocationOverrideCheckboxElement.checked;
  45647. this._geolocationFieldsetElement.disabled = controlsDisabled;
  45648.  
  45649. if (controlsDisabled) {
  45650. WebInspector.userAgentSupport.toggleGeolocationPositionOverride(false);
  45651. return;
  45652. }
  45653.  
  45654. var geolocation = WebInspector.UserAgentSupport.GeolocationPosition.parseUserInput(this._latitudeElement.value, this._longitudeElement.value, this._geolocationErrorElement.checked);
  45655. if (geolocation) {
  45656. this._setGeolocationPosition(geolocation, false, false);
  45657. WebInspector.userAgentSupport.toggleGeolocationPositionOverride(true);
  45658. }
  45659. if (!this._latitudeElement.value)
  45660. this._latitudeElement.focus();
  45661. },
  45662.  
  45663. _applyGeolocationUserInput: function()
  45664. {
  45665. this._setGeolocationPosition(WebInspector.UserAgentSupport.GeolocationPosition.parseUserInput(this._latitudeElement.value.trim(), this._longitudeElement.value.trim(), this._geolocationErrorElement.checked), true, false);
  45666. },
  45667.  
  45668.  
  45669. _setGeolocationPosition: function(geolocation, userInputModified, updateCheckbox)
  45670. {
  45671. if (!geolocation)
  45672. return;
  45673.  
  45674. if (!userInputModified) {
  45675. this._latitudeElement.value = geolocation.latitude;
  45676. this._longitudeElement.value = geolocation.longitude;
  45677. }
  45678.  
  45679. var value = geolocation.toSetting();
  45680. WebInspector.settings.geolocationOverride.set(value);
  45681.  
  45682. if (this._geolocationOverrideCheckboxElement && updateCheckbox) {
  45683. this._geolocationOverrideCheckboxElement.checked = !!geolocation.toSetting();
  45684. this._onGeolocationOverrideCheckboxClicked();
  45685. }
  45686. },
  45687.  
  45688.  
  45689. _createGeolocationOverrideElement: function(geolocation)
  45690. {
  45691. var fieldsetElement = document.createElement("fieldset");
  45692. fieldsetElement.id = "geolocation-override-section";
  45693. this._geolocationFieldsetElement = fieldsetElement;
  45694.  
  45695. var tableElement = fieldsetElement.createChild("table");
  45696. var rowElement = tableElement.createChild("tr");
  45697. var cellElement = rowElement.createChild("td");
  45698. cellElement.appendChild(document.createTextNode(WebInspector.UIString("Geolocation Position") + ":"));
  45699. cellElement = rowElement.createChild("td");
  45700. cellElement.appendChild(document.createTextNode(WebInspector.UIString("Lat = ")));
  45701. this._latitudeElement = this._createInput(cellElement, "geolocation-override-latitude", String(geolocation.latitude), this._applyGeolocationUserInput.bind(this), true);
  45702. cellElement.appendChild(document.createTextNode(" , "));
  45703. cellElement.appendChild(document.createTextNode(WebInspector.UIString("Lon = ")));
  45704. this._longitudeElement = this._createInput(cellElement, "geolocation-override-longitude", String(geolocation.longitude), this._applyGeolocationUserInput.bind(this), true);
  45705. rowElement = tableElement.createChild("tr");
  45706. cellElement = rowElement.createChild("td");
  45707. cellElement.colSpan = 2;
  45708. var geolocationErrorLabelElement = document.createElement("label");
  45709. var geolocationErrorCheckboxElement = geolocationErrorLabelElement.createChild("input");
  45710. geolocationErrorCheckboxElement.id = "geolocation-error";
  45711. geolocationErrorCheckboxElement.type = "checkbox";
  45712. geolocationErrorCheckboxElement.checked = !geolocation || geolocation.error;
  45713. geolocationErrorCheckboxElement.addEventListener("click", this._applyGeolocationUserInput.bind(this), false);
  45714. geolocationErrorLabelElement.appendChild(document.createTextNode(WebInspector.UIString("Emulate position unavailable")));
  45715. this._geolocationErrorElement = geolocationErrorCheckboxElement;
  45716. cellElement.appendChild(geolocationErrorLabelElement);
  45717.  
  45718. return fieldsetElement;
  45719. },
  45720.  
  45721. _createDeviceOrientationOverrideControl: function()
  45722. {
  45723. const deviceOrientationSetting = WebInspector.settings.deviceOrientationOverride.get();
  45724. var deviceOrientation = WebInspector.UserAgentSupport.DeviceOrientation.parseSetting(deviceOrientationSetting);
  45725.  
  45726. var p = document.createElement("p");
  45727. var labelElement = p.createChild("label");
  45728. var checkboxElement = labelElement.createChild("input");
  45729. checkboxElement.id = "device-orientation-override-checkbox";
  45730. checkboxElement.type = "checkbox";
  45731. checkboxElement.checked = false;
  45732. checkboxElement.addEventListener("click", this._onDeviceOrientationOverrideCheckboxClicked.bind(this), false);
  45733. this._deviceOrientationOverrideCheckboxElement = checkboxElement;
  45734. labelElement.appendChild(document.createTextNode(WebInspector.UIString("Override Device Orientation")));
  45735.  
  45736. var deviceOrientationSectionElement = this._createDeviceOrientationOverrideElement(deviceOrientation);
  45737. p.appendChild(deviceOrientationSectionElement);
  45738. this._deviceOrientationSectionElement = deviceOrientationSectionElement;
  45739. this._onDeviceOrientationOverrideCheckboxClicked();
  45740. return p;
  45741. },
  45742.  
  45743. _onDeviceOrientationOverrideCheckboxClicked: function()
  45744. {
  45745. var controlsDisabled = !this._deviceOrientationOverrideCheckboxElement.checked;
  45746. this._deviceOrientationFieldsetElement.disabled = controlsDisabled;
  45747.  
  45748. if (controlsDisabled) {
  45749. WebInspector.userAgentSupport.toggleDeviceOrientationOverride(false);
  45750. return;
  45751. }
  45752.  
  45753. var deviceOrientation = WebInspector.UserAgentSupport.DeviceOrientation.parseUserInput(this._alphaElement.value, this._betaElement.value, this._gammaElement.value);
  45754. if (deviceOrientation) {
  45755. this._setDeviceOrientation(deviceOrientation, false, false);
  45756. WebInspector.userAgentSupport.toggleDeviceOrientationOverride(true);
  45757. }
  45758. if (!this._alphaElement.value)
  45759. this._alphaElement.focus();
  45760. },
  45761.  
  45762. _applyDeviceOrientationUserInput: function()
  45763. {
  45764. this._setDeviceOrientation(WebInspector.UserAgentSupport.DeviceOrientation.parseUserInput(this._alphaElement.value.trim(), this._betaElement.value.trim(), this._gammaElement.value.trim()), true, false);
  45765. },
  45766.  
  45767.  
  45768. _setDeviceOrientation: function(deviceOrientation, userInputModified, updateCheckbox)
  45769. {
  45770. if (!deviceOrientation)
  45771. return;
  45772.  
  45773. if (!userInputModified) {
  45774. this._alphaElement.value = deviceOrientation.alpha;
  45775. this._betaElement.value = deviceOrientation.beta;
  45776. this._gammaElement.value = deviceOrientation.gamma;
  45777. }
  45778.  
  45779. var value = deviceOrientation.toSetting();
  45780. WebInspector.settings.deviceOrientationOverride.set(value);
  45781.  
  45782. if (this._deviceOrientationOverrideCheckboxElement && updateCheckbox) {
  45783. this._deviceOrientationOverrideCheckboxElement.checked = !!deviceOrientation.toSetting();
  45784. this._onDeviceOrientationOverrideCheckboxClicked();
  45785. }
  45786. },
  45787.  
  45788.  
  45789. _createDeviceOrientationOverrideElement: function(deviceOrientation)
  45790. {
  45791. var fieldsetElement = document.createElement("fieldset");
  45792. fieldsetElement.id = "device-orientation-override-section";
  45793. this._deviceOrientationFieldsetElement = fieldsetElement;
  45794.  
  45795. var tableElement = fieldsetElement.createChild("table");
  45796.  
  45797. var rowElement = tableElement.createChild("tr");
  45798. var cellElement = rowElement.createChild("td");
  45799. cellElement.appendChild(document.createTextNode("\u03B1: "));
  45800. this._alphaElement = this._createInput(cellElement, "device-orientation-override-alpha", String(deviceOrientation.alpha), this._applyDeviceOrientationUserInput.bind(this), true);
  45801. cellElement.appendChild(document.createTextNode(" \u03B2: "));
  45802. this._betaElement = this._createInput(cellElement, "device-orientation-override-beta", String(deviceOrientation.beta), this._applyDeviceOrientationUserInput.bind(this), true);
  45803. cellElement.appendChild(document.createTextNode(" \u03B3: "));
  45804. this._gammaElement = this._createInput(cellElement, "device-orientation-override-gamma", String(deviceOrientation.gamma), this._applyDeviceOrientationUserInput.bind(this), true);
  45805.  
  45806. return fieldsetElement;
  45807. },
  45808.  
  45809. _createMediaEmulationElement: function()
  45810. {
  45811. const p = document.createElement("p");
  45812. const labelElement = p.createChild("label");
  45813. const checkboxElement = labelElement.createChild("input");
  45814. checkboxElement.type = "checkbox";
  45815. checkboxElement.checked = false;
  45816. labelElement.appendChild(document.createTextNode(WebInspector.UIString("Emulate CSS media")));
  45817.  
  45818. var mediaSelectElement = p.createChild("select");
  45819. var mediaTypes = WebInspector.CSSStyleModel.MediaTypes;
  45820. var defaultMedia = WebInspector.settings.emulatedCSSMedia.get();
  45821. for (var i = 0; i < mediaTypes.length; ++i) {
  45822. var mediaType = mediaTypes[i];
  45823. if (mediaType === "all") {
  45824.  
  45825. continue;
  45826. }
  45827. var option = document.createElement("option");
  45828. option.text = mediaType;
  45829. option.value = mediaType;
  45830. mediaSelectElement.add(option);
  45831. if (mediaType === defaultMedia)
  45832. mediaSelectElement.selectedIndex = mediaSelectElement.options.length - 1;
  45833. }
  45834. mediaSelectElement.disabled = true;
  45835. var boundListener = this._emulateMediaChanged.bind(this, checkboxElement, mediaSelectElement);
  45836. checkboxElement.addEventListener("click", boundListener, false);
  45837. mediaSelectElement.addEventListener("change", boundListener, false);
  45838. return p;
  45839. },
  45840.  
  45841. _emulateMediaChanged: function(checkbox, select)
  45842. {
  45843. select.disabled = !checkbox.checked;
  45844. if (checkbox.checked) {
  45845. var media = select.options[select.selectedIndex].value;
  45846. WebInspector.settings.emulatedCSSMedia.set(media);
  45847. PageAgent.setEmulatedMedia(media);
  45848. } else
  45849. PageAgent.setEmulatedMedia("");
  45850. WebInspector.cssModel.mediaQueryResultChanged();
  45851. },
  45852.  
  45853. __proto__: WebInspector.View.prototype
  45854. }
  45855.  
  45856.  
  45857.  
  45858.  
  45859.  
  45860.  
  45861.  
  45862.  
  45863.  
  45864.  
  45865.  
  45866.  
  45867. WebInspector.HAREntry = function(request)
  45868. {
  45869. this._request = request;
  45870. }
  45871.  
  45872. WebInspector.HAREntry.prototype = {
  45873.  
  45874. build: function()
  45875. {
  45876. var entry =  {
  45877. startedDateTime: new Date(this._request.startTime * 1000),
  45878. time: WebInspector.HAREntry._toMilliseconds(this._request.duration),
  45879. request: this._buildRequest(),
  45880. response: this._buildResponse(),
  45881. cache: { }, 
  45882. timings: this._buildTimings()
  45883. };
  45884. var page = WebInspector.networkLog.pageLoadForRequest(this._request);
  45885. if (page)
  45886. entry.pageref = "page_" + page.id;
  45887. return entry;
  45888. },
  45889.  
  45890.  
  45891. _buildRequest: function()
  45892. {
  45893. var res = {
  45894. method: this._request.requestMethod,
  45895. url: this._buildRequestURL(this._request.url),
  45896. httpVersion: this._request.requestHttpVersion,
  45897. headers: this._request.requestHeaders,
  45898. queryString: this._buildParameters(this._request.queryParameters || []),
  45899. cookies: this._buildCookies(this._request.requestCookies || []),
  45900. headersSize: this._request.requestHeadersSize,
  45901. bodySize: this.requestBodySize
  45902. };
  45903. if (this._request.requestFormData)
  45904. res.postData = this._buildPostData();
  45905.  
  45906. return res;
  45907. },
  45908.  
  45909.  
  45910. _buildResponse: function()
  45911. {
  45912. return {
  45913. status: this._request.statusCode,
  45914. statusText: this._request.statusText,
  45915. httpVersion: this._request.responseHttpVersion,
  45916. headers: this._request.responseHeaders,
  45917. cookies: this._buildCookies(this._request.responseCookies || []),
  45918. content: this._buildContent(),
  45919. redirectURL: this._request.responseHeaderValue("Location") || "",
  45920. headersSize: this._request.responseHeadersSize,
  45921. bodySize: this.responseBodySize
  45922. };
  45923. },
  45924.  
  45925.  
  45926. _buildContent: function()
  45927. {
  45928. var content = {
  45929. size: this._request.resourceSize,
  45930. mimeType: this._request.mimeType,
  45931.  
  45932. };
  45933. var compression = this.responseCompression;
  45934. if (typeof compression === "number")
  45935. content.compression = compression;
  45936. return content;
  45937. },
  45938.  
  45939.  
  45940. _buildTimings: function()
  45941. {
  45942. var waitForConnection = this._interval("connectStart", "connectEnd");
  45943. var blocked;
  45944. var connect;
  45945. var dns = this._interval("dnsStart", "dnsEnd");
  45946. var send = this._interval("sendStart", "sendEnd");
  45947. var ssl = this._interval("sslStart", "sslEnd");
  45948.  
  45949. if (ssl !== -1 && send !== -1)
  45950. send -= ssl;
  45951.  
  45952. if (this._request.connectionReused) {
  45953. connect = -1;
  45954. blocked = waitForConnection;
  45955. } else {
  45956. blocked = 0;
  45957. connect = waitForConnection;
  45958. if (dns !== -1)
  45959. connect -= dns;
  45960. }
  45961.  
  45962. return {
  45963. blocked: blocked,
  45964. dns: dns,
  45965. connect: connect,
  45966. send: send,
  45967. wait: this._interval("sendEnd", "receiveHeadersEnd"),
  45968. receive: WebInspector.HAREntry._toMilliseconds(this._request.receiveDuration),
  45969. ssl: ssl
  45970. };
  45971. },
  45972.  
  45973.  
  45974. _buildPostData: function()
  45975. {
  45976. var res = {
  45977. mimeType: this._request.requestHeaderValue("Content-Type"),
  45978. text: this._request.requestFormData
  45979. };
  45980. if (this._request.formParameters)
  45981. res.params = this._buildParameters(this._request.formParameters);
  45982. return res;
  45983. },
  45984.  
  45985.  
  45986. _buildParameters: function(parameters)
  45987. {
  45988. return parameters.slice();
  45989. },
  45990.  
  45991.  
  45992. _buildRequestURL: function(url)
  45993. {
  45994. return url.split("#", 2)[0];
  45995. },
  45996.  
  45997.  
  45998. _buildCookies: function(cookies)
  45999. {
  46000. return cookies.map(this._buildCookie.bind(this));
  46001. },
  46002.  
  46003.  
  46004. _buildCookie: function(cookie)
  46005. {
  46006. return {
  46007. name: cookie.name(),
  46008. value: cookie.value(),
  46009. path: cookie.path(),
  46010. domain: cookie.domain(),
  46011. expires: cookie.expiresDate(new Date(this._request.startTime * 1000)),
  46012. httpOnly: cookie.httpOnly(),
  46013. secure: cookie.secure()
  46014. };
  46015. },
  46016.  
  46017.  
  46018. _interval: function(start, end)
  46019. {
  46020. var timing = this._request.timing;
  46021. if (!timing)
  46022. return -1;
  46023. var startTime = timing[start];
  46024. return typeof startTime !== "number" || startTime === -1 ? -1 : Math.round(timing[end] - startTime);
  46025. },
  46026.  
  46027.  
  46028. get requestBodySize()
  46029. {
  46030. return !this._request.requestFormData ? 0 : this._request.requestFormData.length;
  46031. },
  46032.  
  46033.  
  46034. get responseBodySize()
  46035. {
  46036. if (this._request.cached || this._request.statusCode === 304)
  46037. return 0;
  46038. return this._request.transferSize - this._request.responseHeadersSize
  46039. },
  46040.  
  46041.  
  46042. get responseCompression()
  46043. {
  46044. if (this._request.cached || this._request.statusCode === 304)
  46045. return;
  46046. return this._request.resourceSize - (this._request.transferSize - this._request.responseHeadersSize);
  46047. }
  46048. }
  46049.  
  46050.  
  46051. WebInspector.HAREntry._toMilliseconds = function(time)
  46052. {
  46053. return time === -1 ? -1 : Math.round(time * 1000);
  46054. }
  46055.  
  46056.  
  46057. WebInspector.HARLog = function(requests)
  46058. {
  46059. this._requests = requests;
  46060. }
  46061.  
  46062. WebInspector.HARLog.prototype = {
  46063.  
  46064. build: function()
  46065. {
  46066. return {
  46067. version: "1.2",
  46068. creator: this._creator(),
  46069. pages: this._buildPages(),
  46070. entries: this._requests.map(this._convertResource.bind(this))
  46071. }
  46072. },
  46073.  
  46074. _creator: function()
  46075. {
  46076. var webKitVersion = /AppleWebKit\/([^ ]+)/.exec(window.navigator.userAgent);
  46077.  
  46078. return {
  46079. name: "WebInspector",
  46080. version: webKitVersion ? webKitVersion[1] : "n/a"
  46081. };
  46082. },
  46083.  
  46084.  
  46085. _buildPages: function()
  46086. {
  46087. var seenIdentifiers = {};
  46088. var pages = [];
  46089. for (var i = 0; i < this._requests.length; ++i) {
  46090. var page = WebInspector.networkLog.pageLoadForRequest(this._requests[i]);
  46091. if (!page || seenIdentifiers[page.id])
  46092. continue;
  46093. seenIdentifiers[page.id] = true;
  46094. pages.push(this._convertPage(page));
  46095. }
  46096. return pages;
  46097. },
  46098.  
  46099.  
  46100. _convertPage: function(page)
  46101. {
  46102. return {
  46103. startedDateTime: new Date(page.startTime * 1000),
  46104. id: "page_" + page.id,
  46105. title: page.url, 
  46106. pageTimings: {
  46107. onContentLoad: this._pageEventTime(page, page.contentLoadTime),
  46108. onLoad: this._pageEventTime(page, page.loadTime)
  46109. }
  46110. }
  46111. },
  46112.  
  46113.  
  46114. _convertResource: function(request)
  46115. {
  46116. return (new WebInspector.HAREntry(request)).build();
  46117. },
  46118.  
  46119.  
  46120. _pageEventTime: function(page, time)
  46121. {
  46122. var startTime = page.startTime;
  46123. if (time === -1 || startTime === -1)
  46124. return -1;
  46125. return WebInspector.HAREntry._toMilliseconds(time - startTime);
  46126. }
  46127. }
  46128.  
  46129.  
  46130. WebInspector.HARWriter = function()
  46131. {
  46132. }
  46133.  
  46134. WebInspector.HARWriter.prototype = {
  46135.  
  46136. write: function(stream, requests, progress)
  46137. {
  46138. this._stream = stream;
  46139. this._harLog = (new WebInspector.HARLog(requests)).build();
  46140. this._pendingRequests = 1; 
  46141. var entries = this._harLog.entries;
  46142. for (var i = 0; i < entries.length; ++i) {
  46143. var content = requests[i].content;
  46144. if (typeof content === "undefined" && requests[i].finished) {
  46145. ++this._pendingRequests;
  46146. requests[i].requestContent(this._onContentAvailable.bind(this, entries[i]));
  46147. } else if (content !== null)
  46148. entries[i].response.content.text = content;
  46149. }
  46150. var compositeProgress = new WebInspector.CompositeProgress(progress);
  46151. this._writeProgress = compositeProgress.createSubProgress();
  46152. if (--this._pendingRequests) {
  46153. this._requestsProgress = compositeProgress.createSubProgress();
  46154. this._requestsProgress.setTitle(WebInspector.UIString("Collecting contentΓǪ"));
  46155. this._requestsProgress.setTotalWork(this._pendingRequests);
  46156. } else
  46157. this._beginWrite();
  46158. },
  46159.  
  46160.  
  46161. _onContentAvailable: function(entry, content, contentEncoded, mimeType)
  46162. {
  46163. if (content !== null)
  46164. entry.response.content.text = content;
  46165. if (this._requestsProgress)
  46166. this._requestsProgress.worked();
  46167. if (!--this._pendingRequests) {
  46168. this._requestsProgress.done();
  46169. this._beginWrite();
  46170. }
  46171. },
  46172.  
  46173. _beginWrite: function()
  46174. {
  46175. const jsonIndent = 2;
  46176. this._text = JSON.stringify({log: this._harLog}, null, jsonIndent);
  46177. this._writeProgress.setTitle(WebInspector.UIString("Writing fileΓǪ"));
  46178. this._writeProgress.setTotalWork(this._text.length);
  46179. this._bytesWritten = 0;
  46180. this._writeNextChunk(this._stream);
  46181. },
  46182.  
  46183.  
  46184. _writeNextChunk: function(stream, error)
  46185. {
  46186. if (this._bytesWritten >= this._text.length || error) {
  46187. stream.close();
  46188. this._writeProgress.done();
  46189. return;
  46190. }
  46191. const chunkSize = 100000;
  46192. var text = this._text.substring(this._bytesWritten, this._bytesWritten + chunkSize);
  46193. this._bytesWritten += text.length;
  46194. stream.write(text, this._writeNextChunk.bind(this));
  46195. this._writeProgress.setWorked(this._bytesWritten);
  46196. }
  46197. }
  46198.  
  46199.  
  46200.  
  46201.  
  46202.  
  46203.  
  46204.  
  46205.  
  46206.  
  46207.  
  46208.  
  46209.  
  46210.  
  46211. WebInspector.CookieParser = function()
  46212. {
  46213. }
  46214.  
  46215.  
  46216. WebInspector.CookieParser.KeyValue = function(key, value, position)
  46217. {
  46218. this.key = key;
  46219. this.value = value;
  46220. this.position = position;
  46221. }
  46222.  
  46223. WebInspector.CookieParser.prototype = {
  46224.  
  46225. cookies: function()
  46226. {
  46227. return this._cookies;
  46228. },
  46229.  
  46230.  
  46231. parseCookie: function(cookieHeader)
  46232. {
  46233. if (!this._initialize(cookieHeader))
  46234. return null;
  46235.  
  46236. for (var kv = this._extractKeyValue(); kv; kv = this._extractKeyValue()) {
  46237. if (kv.key.charAt(0) === "$" && this._lastCookie)
  46238. this._lastCookie.addAttribute(kv.key.slice(1), kv.value);
  46239. else if (kv.key.toLowerCase() !== "$version" && typeof kv.value === "string")
  46240. this._addCookie(kv, WebInspector.Cookie.Type.Request);
  46241. this._advanceAndCheckCookieDelimiter();
  46242. }
  46243. this._flushCookie();
  46244. return this._cookies;
  46245. },
  46246.  
  46247.  
  46248. parseSetCookie: function(setCookieHeader)
  46249. {
  46250. if (!this._initialize(setCookieHeader))
  46251. return null;
  46252. for (var kv = this._extractKeyValue(); kv; kv = this._extractKeyValue()) {
  46253. if (this._lastCookie)
  46254. this._lastCookie.addAttribute(kv.key, kv.value);
  46255. else
  46256. this._addCookie(kv, WebInspector.Cookie.Type.Response);
  46257. if (this._advanceAndCheckCookieDelimiter())
  46258. this._flushCookie();
  46259. }
  46260. this._flushCookie();
  46261. return this._cookies;
  46262. },
  46263.  
  46264.  
  46265. _initialize: function(headerValue)
  46266. {
  46267. this._input = headerValue;
  46268. if (typeof headerValue !== "string")
  46269. return false;
  46270. this._cookies = [];
  46271. this._lastCookie = null;
  46272. this._originalInputLength = this._input.length;
  46273. return true;
  46274. },
  46275.  
  46276. _flushCookie: function()
  46277. {
  46278. if (this._lastCookie)
  46279. this._lastCookie.setSize(this._originalInputLength - this._input.length - this._lastCookiePosition);
  46280. this._lastCookie = null;
  46281. },
  46282.  
  46283.  
  46284. _extractKeyValue: function()
  46285. {
  46286. if (!this._input || !this._input.length)
  46287. return null;
  46288.  
  46289.  
  46290.  
  46291.  
  46292.  
  46293. var keyValueMatch = /^[ \t]*([^\s=;]+)[ \t]*(?:=[ \t]*([^;\n]*))?/.exec(this._input);
  46294.         if (!keyValueMatch) {
  46295.             console.log("Failed parsing cookie header before: " + this._input);
  46296.             return null;
  46297.         }
  46298.  
  46299.         var result = new WebInspector.CookieParser.KeyValue(keyValueMatch[1], keyValueMatch[2] && keyValueMatch[2].trim(), this._originalInputLength - this._input.length);
  46300.         this._input = this._input.slice(keyValueMatch[0].length);
  46301.         return result;
  46302.     },
  46303.  
  46304.     /**
  46305. * @return {boolean}
  46306. */
  46307. _advanceAndCheckCookieDelimiter: function()
  46308. {
  46309. var match = /^\s*[\n;]\s*/.exec(this._input);
  46310. if (!match)
  46311. return false;
  46312. this._input = this._input.slice(match[0].length);
  46313. return match[0].match("\n") !== null;
  46314. },
  46315.  
  46316.  
  46317. _addCookie: function(keyValue, type)
  46318. {
  46319. if (this._lastCookie)
  46320. this._lastCookie.setSize(keyValue.position - this._lastCookiePosition);
  46321.  
  46322.  
  46323. this._lastCookie = keyValue.value ? new WebInspector.Cookie(keyValue.key, keyValue.value, type) :
  46324. new WebInspector.Cookie("", keyValue.key, type);
  46325. this._lastCookiePosition = keyValue.position;
  46326. this._cookies.push(this._lastCookie);
  46327. }
  46328. };
  46329.  
  46330.  
  46331. WebInspector.CookieParser.parseCookie = function(header)
  46332. {
  46333. return (new WebInspector.CookieParser()).parseCookie(header);
  46334. }
  46335.  
  46336.  
  46337. WebInspector.CookieParser.parseSetCookie = function(header)
  46338. {
  46339. return (new WebInspector.CookieParser()).parseSetCookie(header);
  46340. }
  46341.  
  46342.  
  46343. WebInspector.Cookie = function(name, value, type)
  46344. {
  46345. this._name = name;
  46346. this._value = value;
  46347. this._type = type;
  46348. this._attributes = {};
  46349. }
  46350.  
  46351. WebInspector.Cookie.prototype = {
  46352.  
  46353. name: function()
  46354. {
  46355. return this._name;
  46356. },
  46357.  
  46358.  
  46359. value: function()
  46360. {
  46361. return this._value;
  46362. },
  46363.  
  46364.  
  46365. type: function()
  46366. {
  46367. return this._type;
  46368. },
  46369.  
  46370.  
  46371. httpOnly: function()
  46372. {
  46373. return "httponly" in this._attributes;
  46374. },
  46375.  
  46376.  
  46377. secure: function()
  46378. {
  46379. return "secure" in this._attributes;
  46380. },
  46381.  
  46382.  
  46383. session: function()
  46384. {
  46385.  
  46386.  
  46387. return !("expires" in this._attributes || "max-age" in this._attributes);
  46388. },
  46389.  
  46390.  
  46391. path: function()
  46392. {
  46393. return this._attributes["path"];
  46394. },
  46395.  
  46396.  
  46397. port: function()
  46398. {
  46399. return this._attributes["port"];
  46400. },
  46401.  
  46402.  
  46403. domain: function()
  46404. {
  46405. return this._attributes["domain"];
  46406. },
  46407.  
  46408.  
  46409. expires: function()
  46410. {
  46411. return this._attributes["expires"];
  46412. },
  46413.  
  46414.  
  46415. maxAge: function()
  46416. {
  46417. return this._attributes["max-age"];
  46418. },
  46419.  
  46420.  
  46421. size: function()
  46422. {
  46423. return this._size;
  46424. },
  46425.  
  46426.  
  46427. setSize: function(size)
  46428. {
  46429. this._size = size;
  46430. },
  46431.  
  46432.  
  46433. expiresDate: function(requestDate)
  46434. {
  46435.  
  46436. if (this.maxAge()) {
  46437. var targetDate = requestDate === null ? new Date() : requestDate;
  46438. return new Date(targetDate.getTime() + 1000 * this.maxAge());
  46439. }
  46440.  
  46441. if (this.expires())
  46442. return new Date(this.expires());
  46443.  
  46444. return null;
  46445. },
  46446.  
  46447.  
  46448. attributes: function()
  46449. {
  46450. return this._attributes;
  46451. },
  46452.  
  46453.  
  46454. addAttribute: function(key, value)
  46455. {
  46456. this._attributes[key.toLowerCase()] = value;
  46457. }
  46458. }
  46459.  
  46460.  
  46461. WebInspector.Cookie.Type = {
  46462. Request: 0,
  46463. Response: 1
  46464. };
  46465.  
  46466. WebInspector.Cookies = {}
  46467.  
  46468. WebInspector.Cookies.getCookiesAsync = function(callback)
  46469. {
  46470.  
  46471. function mycallback(error, cookies, cookiesString)
  46472. {
  46473. if (error)
  46474. return;
  46475. if (cookiesString)
  46476. callback(WebInspector.Cookies.buildCookiesFromString(cookiesString), false);
  46477. else
  46478. callback(cookies.map(WebInspector.Cookies.buildCookieProtocolObject), true);
  46479. }
  46480.  
  46481. PageAgent.getCookies(mycallback);
  46482. }
  46483.  
  46484.  
  46485. WebInspector.Cookies.buildCookiesFromString = function(rawCookieString)
  46486. {
  46487. var rawCookies = rawCookieString.split(/;\s*/);
  46488. var cookies = [];
  46489.  
  46490. if (!(/^\s*$/.test(rawCookieString))) {
  46491. for (var i = 0; i < rawCookies.length; ++i) {
  46492. var rawCookie = rawCookies[i];
  46493. var delimIndex = rawCookie.indexOf("=");
  46494. var name = rawCookie.substring(0, delimIndex);
  46495. var value = rawCookie.substring(delimIndex + 1);
  46496. var size = name.length + value.length;
  46497. var cookie = new WebInspector.Cookie(name, value, null);
  46498. cookie.setSize(size);
  46499. cookies.push(cookie);
  46500. }
  46501. }
  46502.  
  46503. return cookies;
  46504. }
  46505.  
  46506.  
  46507. WebInspector.Cookies.buildCookieProtocolObject = function(protocolCookie)
  46508. {
  46509. var cookie = new WebInspector.Cookie(protocolCookie.name, protocolCookie.value, null);
  46510. cookie.addAttribute("domain", protocolCookie["domain"]);
  46511. cookie.addAttribute("path", protocolCookie["path"]);
  46512. cookie.addAttribute("port", protocolCookie["port"]);
  46513. if (protocolCookie["expires"])
  46514. cookie.addAttribute("expires", protocolCookie["expires"]);
  46515. if (protocolCookie["httpOnly"])
  46516. cookie.addAttribute("httpOnly");
  46517. if (protocolCookie["secure"])
  46518. cookie.addAttribute("secure");
  46519. cookie.setSize(protocolCookie["size"]);
  46520. return cookie;
  46521. }
  46522.  
  46523.  
  46524. WebInspector.Cookies.cookieMatchesResourceURL = function(cookie, resourceURL)
  46525. {
  46526. var url = resourceURL.asParsedURL();
  46527. if (!url || !WebInspector.Cookies.cookieDomainMatchesResourceDomain(cookie.domain(), url.host))
  46528. return false;
  46529. return (url.path.startsWith(cookie.path())
  46530. && (!cookie.port() || url.port == cookie.port())
  46531. && (!cookie.secure() || url.scheme === "https"));
  46532. }
  46533.  
  46534.  
  46535. WebInspector.Cookies.cookieDomainMatchesResourceDomain = function(cookieDomain, resourceDomain)
  46536. {
  46537. if (cookieDomain.charAt(0) !== '.')
  46538. return resourceDomain === cookieDomain;
  46539. return !!resourceDomain.match(new RegExp("^([^\\.]+\\.)*" + cookieDomain.substring(1).escapeForRegExp() + "$", "i"));
  46540. }
  46541.  
  46542.  
  46543.  
  46544.  
  46545.  
  46546.  
  46547. WebInspector.Toolbar = function()
  46548. {
  46549. this.element = document.getElementById("toolbar");
  46550. WebInspector.installDragHandle(this.element, this._toolbarDragStart.bind(this), this._toolbarDrag.bind(this), this._toolbarDragEnd.bind(this), "default");
  46551.  
  46552. this._dropdownButton = document.getElementById("toolbar-dropdown-arrow");
  46553. this._dropdownButton.addEventListener("click", this._toggleDropdown.bind(this), false);
  46554.  
  46555. document.getElementById("close-button-left").addEventListener("click", this._onClose, true);
  46556. document.getElementById("close-button-right").addEventListener("click", this._onClose, true);
  46557. }
  46558.  
  46559. WebInspector.Toolbar.prototype = {
  46560. resize: function()
  46561. {
  46562. this._updateDropdownButtonAndHideDropdown();
  46563. },
  46564.  
  46565.  
  46566. addPanel: function(panelDescriptor)
  46567. {
  46568. this.element.appendChild(this._createPanelToolbarItem(panelDescriptor));
  46569. this.resize();
  46570. },
  46571.  
  46572.  
  46573. _createPanelToolbarItem: function(panelDescriptor)
  46574. {
  46575. var toolbarItem = document.createElement("button");
  46576. toolbarItem.className = "toolbar-item toggleable";
  46577. toolbarItem.panelDescriptor = panelDescriptor;
  46578. toolbarItem.addStyleClass(panelDescriptor.name());
  46579.  
  46580. function onToolbarItemClicked()
  46581. {
  46582. this._updateDropdownButtonAndHideDropdown();
  46583. WebInspector.inspectorView.setCurrentPanel(panelDescriptor.panel());
  46584. }
  46585. toolbarItem.addEventListener("click", onToolbarItemClicked.bind(this), false);
  46586.  
  46587. function panelSelected()
  46588. {
  46589. if (WebInspector.inspectorView.currentPanel() && panelDescriptor.name() === WebInspector.inspectorView.currentPanel().name)
  46590. toolbarItem.addStyleClass("toggled-on");
  46591. else
  46592. toolbarItem.removeStyleClass("toggled-on");
  46593. }
  46594. WebInspector.inspectorView.addEventListener(WebInspector.InspectorView.Events.PanelSelected, panelSelected);
  46595.  
  46596. var iconElement = toolbarItem.createChild("div", "toolbar-icon");
  46597. toolbarItem.createChild("div", "toolbar-label").textContent = panelDescriptor.title();
  46598. if (panelDescriptor.iconURL()) {
  46599. iconElement.addStyleClass("custom-toolbar-icon");
  46600. iconElement.style.backgroundImage = "url(" + panelDescriptor.iconURL() + ")";
  46601. }
  46602. panelSelected();
  46603. return toolbarItem;
  46604. },
  46605.  
  46606.  
  46607. setDockedToBottom: function(dockedToBottom)
  46608. {
  46609. this._isDockedToBottom = dockedToBottom;
  46610. },
  46611.  
  46612.  
  46613. _toolbarDragStart: function(event)
  46614. {
  46615. if ((!this._isDockedToBottom && WebInspector.platformFlavor() !== WebInspector.PlatformFlavor.MacLeopard && WebInspector.platformFlavor() !== WebInspector.PlatformFlavor.MacSnowLeopard) || WebInspector.port() == "qt")
  46616. return false;
  46617.  
  46618. var target = event.target;
  46619. if (target.hasStyleClass("toolbar-item") && target.hasStyleClass("toggleable"))
  46620. return false;
  46621.  
  46622. if (target !== this.element && !target.hasStyleClass("toolbar-item"))
  46623. return false;
  46624.  
  46625. this.element.lastScreenX = event.screenX;
  46626. this.element.lastScreenY = event.screenY;
  46627. return true;
  46628. },
  46629.  
  46630. _toolbarDragEnd: function(event)
  46631. {
  46632. delete this.element.lastScreenX;
  46633. delete this.element.lastScreenY;
  46634. },
  46635.  
  46636. _toolbarDrag: function(event)
  46637. {
  46638. if (this._isDockedToBottom) {
  46639. var height = window.innerHeight - (event.screenY - this.element.lastScreenY);
  46640.  
  46641. InspectorFrontendHost.setAttachedWindowHeight(height);
  46642. } else {
  46643. var x = event.screenX - this.element.lastScreenX;
  46644. var y = event.screenY - this.element.lastScreenY;
  46645.  
  46646.  
  46647.  
  46648. InspectorFrontendHost.moveWindowBy(x, y);
  46649. }
  46650.  
  46651. this.element.lastScreenX = event.screenX;
  46652. this.element.lastScreenY = event.screenY;
  46653.  
  46654. event.preventDefault();
  46655. },
  46656.  
  46657. _onClose: function()
  46658. {
  46659. WebInspector.close();
  46660. },
  46661.  
  46662. _setDropdownVisible: function(visible)
  46663. {
  46664. if (!this._dropdown) {
  46665. if (!visible)
  46666. return;
  46667. this._dropdown = new WebInspector.ToolbarDropdown(this);
  46668. }
  46669. if (visible)
  46670. this._dropdown.show();
  46671. else
  46672. this._dropdown.hide();
  46673. },
  46674.  
  46675. _toggleDropdown: function()
  46676. {
  46677. this._setDropdownVisible(!this._dropdown || !this._dropdown.visible);
  46678. },
  46679.  
  46680. _updateDropdownButtonAndHideDropdown: function()
  46681. {
  46682. WebInspector.invokeOnceAfterBatchUpdate(this, this._innerUpdateDropdownButtonAndHideDropdown);
  46683. },
  46684.  
  46685. _innerUpdateDropdownButtonAndHideDropdown: function()
  46686. {
  46687. this._setDropdownVisible(false);
  46688.  
  46689. if (this.element.scrollHeight > this.element.offsetHeight)
  46690. this._dropdownButton.removeStyleClass("hidden");
  46691. else
  46692. this._dropdownButton.addStyleClass("hidden");
  46693. }
  46694. }
  46695.  
  46696.  
  46697. WebInspector.ToolbarDropdown = function(toolbar)
  46698. {
  46699. this._toolbar = toolbar;
  46700. this._arrow = document.getElementById("toolbar-dropdown-arrow");
  46701. this.element = document.createElement("div");
  46702. this.element.id = "toolbar-dropdown";
  46703. this.element.className = "toolbar-small";
  46704. this._contentElement = this.element.createChild("div", "scrollable-content");
  46705. this._contentElement.tabIndex = 0;
  46706. this._contentElement.addEventListener("keydown", this._onKeyDown.bind(this), true);
  46707. }
  46708.  
  46709. WebInspector.ToolbarDropdown.prototype = {
  46710. show: function()
  46711. {
  46712. if (this.visible)
  46713. return;
  46714. var style = this.element.style;
  46715. this._populate();
  46716. var top = this._arrow.totalOffsetTop() + this._arrow.clientHeight;
  46717. this._arrow.addStyleClass("dropdown-visible");
  46718. this.element.style.top = top + "px";
  46719. this.element.style.right = window.innerWidth - this._arrow.totalOffsetLeft() - this._arrow.clientWidth + "px";
  46720. this._contentElement.style.maxHeight = window.innerHeight - top - 20 + "px";
  46721. this._toolbar.element.appendChild(this.element);
  46722. },
  46723.  
  46724. hide: function()
  46725. {
  46726. if (!this.visible)
  46727. return;
  46728. this._arrow.removeStyleClass("dropdown-visible");
  46729. this.element.parentNode.removeChild(this.element);
  46730. this._contentElement.removeChildren();
  46731. },
  46732.  
  46733. get visible()
  46734. {
  46735. return !!this.element.parentNode;
  46736. },
  46737.  
  46738. _populate: function()
  46739. {
  46740. var toolbarItems = this._toolbar.element.querySelectorAll(".toolbar-item.toggleable");
  46741.  
  46742. for (var i = 0; i < toolbarItems.length; ++i) {
  46743. if (toolbarItems[i].offsetTop > 1)
  46744. this._contentElement.appendChild(this._toolbar._createPanelToolbarItem(toolbarItems[i].panelDescriptor));
  46745. }
  46746. },
  46747.  
  46748. _onKeyDown: function(event)
  46749. {
  46750. if (event.keyCode !== WebInspector.KeyboardShortcut.Keys.Esc.code)
  46751. return;
  46752. event.consume();
  46753. this.hide();
  46754. }
  46755. }
  46756.  
  46757.  
  46758. WebInspector.toolbar = null;
  46759.  
  46760.  
  46761.  
  46762.  
  46763.  
  46764.  
  46765. WebInspector.SearchController = function()
  46766. {
  46767. this._element = document.createElement("table");
  46768. this._element.className = "toolbar-search";
  46769. this._element.cellSpacing = 0;
  46770.  
  46771. this._firstRowElement = this._element.createChild("tr");
  46772. this._secondRowElement = this._element.createChild("tr", "hidden");
  46773.  
  46774.  
  46775. var searchControlElementColumn = this._firstRowElement.createChild("td"); 
  46776. this._searchControlElement = searchControlElementColumn.createChild("span", "toolbar-search-control");
  46777. this._searchInputElement = this._searchControlElement.createChild("input", "search-replace");
  46778. this._searchInputElement.id = "search-input-field";
  46779. this._searchInputElement.placeholder = WebInspector.UIString("Find");
  46780.  
  46781. this._filterControlElement = searchControlElementColumn.createChild("span", "toolbar-search-control");
  46782. this._filterControlElement.addStyleClass("hidden");
  46783. this._filterInputElement = this._filterControlElement.createChild("input", "filter");
  46784. this._filterInputElement.id = "filter-input-field";
  46785. this._filterInputElement.placeholder = WebInspector.UIString("Filter");
  46786.  
  46787. this._matchesElement = this._searchControlElement.createChild("label", "search-results-matches");
  46788. this._matchesElement.setAttribute("for", "search-input-field");
  46789.  
  46790. var searchNavigationElement = this._searchControlElement.createChild("div", "toolbar-search-navigation-controls");
  46791.  
  46792. this._searchNavigationPrevElement = searchNavigationElement.createChild("div", "toolbar-search-navigation toolbar-search-navigation-prev");
  46793. this._searchNavigationPrevElement.addEventListener("click", this._onPrevButtonSearch.bind(this), false);
  46794. this._searchNavigationPrevElement.title = WebInspector.UIString("Search Previous");
  46795.  
  46796. this._searchNavigationNextElement = searchNavigationElement.createChild("div", "toolbar-search-navigation toolbar-search-navigation-next"); 
  46797. this._searchNavigationNextElement.addEventListener("click", this._onNextButtonSearch.bind(this), false);
  46798. this._searchNavigationNextElement.title = WebInspector.UIString("Search Next");
  46799.  
  46800. this._searchInputElement.addEventListener("mousedown", this._onSearchFieldManualFocus.bind(this), false); 
  46801. this._searchInputElement.addEventListener("keydown", this._onKeyDown.bind(this), true);
  46802. this._filterInputElement.addEventListener("keydown", this._onKeyDown.bind(this), true);
  46803. this._filterInputElement.addEventListener("input", this._onFilterInput.bind(this), false);
  46804. this._searchInputElement.addEventListener("input", this._onSearchInput.bind(this), false);
  46805.  
  46806. this._replaceInputElement = this._secondRowElement.createChild("td").createChild("input", "search-replace toolbar-replace-control");
  46807. this._replaceInputElement.addEventListener("keydown", this._onKeyDown.bind(this), true);
  46808. this._replaceInputElement.placeholder = WebInspector.UIString("Replace");
  46809.  
  46810.  
  46811. this._findButtonElement = this._firstRowElement.createChild("td").createChild("button", "hidden");
  46812. this._findButtonElement.textContent = WebInspector.UIString("Find");
  46813. this._findButtonElement.tabIndex = -1;
  46814. this._findButtonElement.addEventListener("click", this._onNextButtonSearch.bind(this), false);
  46815.  
  46816. this._replaceButtonElement = this._secondRowElement.createChild("td").createChild("button");
  46817. this._replaceButtonElement.textContent = WebInspector.UIString("Replace");
  46818. this._replaceButtonElement.disabled = true;
  46819. this._replaceButtonElement.tabIndex = -1;
  46820. this._replaceButtonElement.addEventListener("click", this._replace.bind(this), false);
  46821.  
  46822.  
  46823. this._prevButtonElement = this._firstRowElement.createChild("td").createChild("button", "hidden");
  46824. this._prevButtonElement.textContent = WebInspector.UIString("Previous");
  46825. this._prevButtonElement.disabled = true;
  46826. this._prevButtonElement.tabIndex = -1;
  46827. this._prevButtonElement.addEventListener("click", this._onPrevButtonSearch.bind(this), false);
  46828.  
  46829. this._replaceAllButtonElement = this._secondRowElement.createChild("td").createChild("button");
  46830. this._replaceAllButtonElement.textContent = WebInspector.UIString("Replace All");
  46831. this._replaceAllButtonElement.addEventListener("click", this._replaceAll.bind(this), false);
  46832.  
  46833.  
  46834. this._replaceElement = this._firstRowElement.createChild("td").createChild("span");
  46835.  
  46836. this._replaceCheckboxElement = this._replaceElement.createChild("input");
  46837. this._replaceCheckboxElement.type = "checkbox";
  46838. this._replaceCheckboxElement.id = "search-replace-trigger";
  46839. this._replaceCheckboxElement.addEventListener("click", this._updateSecondRowVisibility.bind(this), false);
  46840.  
  46841. this._replaceLabelElement = this._replaceElement.createChild("label");
  46842. this._replaceLabelElement.textContent = WebInspector.UIString("Replace");
  46843. this._replaceLabelElement.setAttribute("for", "search-replace-trigger");
  46844.  
  46845.  
  46846. this._filterCheckboxContainer = this._firstRowElement.createChild("td").createChild("span");
  46847.  
  46848. this._filterCheckboxElement = this._filterCheckboxContainer.createChild("input");
  46849. this._filterCheckboxElement.type = "checkbox";
  46850. this._filterCheckboxElement.id = "filter-trigger";
  46851. this._filterCheckboxElement.addEventListener("click", this._filterCheckboxClick.bind(this), false);
  46852.  
  46853. this._filterLabelElement = this._filterCheckboxContainer.createChild("label");
  46854. this._filterLabelElement.textContent = WebInspector.UIString("Filter");
  46855. this._filterLabelElement.setAttribute("for", "filter-trigger");
  46856.  
  46857.  
  46858. var cancelButtonElement = this._firstRowElement.createChild("td").createChild("button");
  46859. cancelButtonElement.textContent = WebInspector.UIString("Cancel");
  46860. cancelButtonElement.tabIndex = -1;
  46861. cancelButtonElement.addEventListener("click", this.cancelSearch.bind(this), false);
  46862. }
  46863.  
  46864. WebInspector.SearchController.prototype = {
  46865. updateSearchMatchesCount: function(matches, panel)
  46866. {
  46867. if (!panel)
  46868. panel = WebInspector.inspectorView.currentPanel();
  46869.  
  46870. panel.currentSearchMatches = matches;
  46871.  
  46872. if (panel === WebInspector.inspectorView.currentPanel())
  46873. this._updateSearchMatchesCountAndCurrentMatchIndex(WebInspector.inspectorView.currentPanel().currentQuery ? matches : 0, -1);
  46874. },
  46875.  
  46876. updateCurrentMatchIndex: function(currentMatchIndex, panel)
  46877. {
  46878. if (panel === WebInspector.inspectorView.currentPanel())
  46879. this._updateSearchMatchesCountAndCurrentMatchIndex(panel.currentSearchMatches, currentMatchIndex);
  46880. },
  46881.  
  46882. cancelSearch: function()
  46883. {
  46884. if (!this._searchIsVisible)
  46885. return;
  46886. if (this._filterCheckboxElement.checked) {
  46887. this._filterCheckboxElement.checked = false;
  46888. this._switchFilterToSearch();
  46889. delete this._searchIsVisible;
  46890. WebInspector.inspectorView.setFooterElement(null);
  46891. this.resetSearch();
  46892. },
  46893.  
  46894. resetSearch: function()
  46895. {
  46896. this._performSearch("", false, false);
  46897. this._updateReplaceVisibility();
  46898. this._matchesElement.textContent = "";
  46899. },
  46900.  
  46901. disableSearchUntilExplicitAction: function()
  46902. {
  46903. this._performSearch("", false, false);
  46904. },
  46905.  
  46906.  
  46907. handleShortcut: function(event)
  46908. {
  46909. var isMac = WebInspector.isMac();
  46910.  
  46911. switch (event.keyIdentifier) {
  46912. case "U+0046": 
  46913. if (isMac)
  46914. var isFindKey = event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey;
  46915. else
  46916. var isFindKey = event.ctrlKey && !event.metaKey && !event.altKey && !event.shiftKey;
  46917.  
  46918. if (isFindKey) {
  46919. this.showSearchField();
  46920. event.consume(true);
  46921. return true;
  46922. }
  46923. break;
  46924.  
  46925. case "F3":
  46926. if (!isMac) {
  46927. this.showSearchField();
  46928. event.consume();
  46929. }
  46930. break;
  46931.  
  46932. case "U+0047": 
  46933. var currentPanel = WebInspector.inspectorView.currentPanel();
  46934.  
  46935. if (isMac && event.metaKey && !event.ctrlKey && !event.altKey) {
  46936. if (event.shiftKey)
  46937. currentPanel.jumpToPreviousSearchResult();
  46938. else
  46939. currentPanel.jumpToNextSearchResult();
  46940. event.consume(true);
  46941. return true;
  46942. }
  46943. break;
  46944. }
  46945. return false;
  46946. },
  46947.  
  46948. _updateSearchNavigationButtonState: function(enabled)
  46949. {
  46950. this._replaceButtonElement.disabled = !enabled;
  46951. this._prevButtonElement.disabled = !enabled;
  46952. var panel = WebInspector.inspectorView.currentPanel();
  46953. if (enabled) {
  46954. this._searchNavigationPrevElement.addStyleClass("enabled");
  46955. this._searchNavigationNextElement.addStyleClass("enabled");
  46956. } else {
  46957. this._searchNavigationPrevElement.removeStyleClass("enabled");
  46958. this._searchNavigationNextElement.removeStyleClass("enabled");
  46959. }
  46960. },
  46961.  
  46962.  
  46963. _updateSearchMatchesCountAndCurrentMatchIndex: function(matches, currentMatchIndex)
  46964. {
  46965. if (matches === 0 || currentMatchIndex >= 0)
  46966. this._matchesElement.textContent = WebInspector.UIString("%d of %d", currentMatchIndex + 1, matches);
  46967. this._updateSearchNavigationButtonState(matches > 0);
  46968. },
  46969.  
  46970. showSearchField: function()
  46971. {
  46972. WebInspector.inspectorView.setFooterElement(this._element);
  46973. this._updateReplaceVisibility();
  46974. this._updateFilterVisibility();
  46975. var selection = window.getSelection();
  46976. if (selection.rangeCount)
  46977. this._searchInputElement.value = selection.toString().replace(/\r?\n.*/, "");
  46978. this._searchInputElement.focus();
  46979. this._searchInputElement.select();
  46980. this._searchIsVisible = true;
  46981. },
  46982.  
  46983. _switchFilterToSearch: function()
  46984. {
  46985. this._filterControlElement.addStyleClass("hidden");
  46986. this._searchControlElement.removeStyleClass("hidden");
  46987. this._searchInputElement.focus();
  46988. this._searchInputElement.select();
  46989. this._searchInputElement.value = this._filterInputElement.value;
  46990. this.resetFilter();
  46991. },
  46992.  
  46993. _switchSearchToFilter: function()
  46994. {
  46995. this._filterControlElement.removeStyleClass("hidden");
  46996. this._searchControlElement.addStyleClass("hidden");
  46997. this._filterInputElement.focus();
  46998. this._filterInputElement.select();
  46999. this._filterInputElement.value = this._searchInputElement.value;
  47000. this.resetSearch();
  47001. },
  47002.  
  47003. _updateFilterVisibility: function()
  47004. {
  47005. if (WebInspector.inspectorView.currentPanel().canFilter())
  47006. this._filterCheckboxContainer.removeStyleClass("hidden");
  47007. else
  47008. this._filterCheckboxContainer.addStyleClass("hidden");
  47009. },
  47010.  
  47011. _updateReplaceVisibility: function()
  47012. {
  47013. var panel = WebInspector.inspectorView.currentPanel();
  47014. if (panel && panel.canSearchAndReplace())
  47015. this._replaceElement.removeStyleClass("hidden");
  47016. else {
  47017. this._replaceElement.addStyleClass("hidden");
  47018. this._replaceCheckboxElement.checked = false;
  47019. this._updateSecondRowVisibility();
  47020. }
  47021. },
  47022.  
  47023. _onSearchFieldManualFocus: function(event)
  47024. {
  47025. WebInspector.setCurrentFocusElement(event.target);
  47026. },
  47027.  
  47028. _onKeyDown: function(event)
  47029. {
  47030.  
  47031. if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Esc.code) {
  47032. event.consume(true);
  47033. this.cancelSearch();
  47034. WebInspector.setCurrentFocusElement(WebInspector.previousFocusElement());
  47035. if (WebInspector.currentFocusElement() === event.target)
  47036. WebInspector.currentFocusElement().select();
  47037. return false;
  47038. }
  47039.  
  47040. if (isEnterKey(event)) {
  47041. if (event.target === this._searchInputElement)
  47042. this._performSearch(event.target.value, true, event.shiftKey);
  47043. else if (event.target === this._replaceInputElement)
  47044. this._replace();
  47045. }
  47046. },
  47047.  
  47048. _onNextButtonSearch: function(event)
  47049. {
  47050.  
  47051. this._performSearch(this._searchInputElement.value, true, false);
  47052. this._searchInputElement.focus();
  47053. },
  47054.  
  47055. _onPrevButtonSearch: function(event)
  47056. {
  47057. if (!this._searchNavigationPrevElement.hasStyleClass("enabled"))
  47058. return;
  47059.  
  47060. this._performSearch(this._searchInputElement.value, true, true);
  47061. this._searchInputElement.focus();
  47062. },
  47063.  
  47064.  
  47065. _performSearch: function(query, forceSearch, isBackwardSearch)
  47066. {
  47067. if (!query || !query.length) {
  47068. delete this._currentQuery;
  47069.  
  47070. for (var panelName in WebInspector.panels) {
  47071. var panel = WebInspector.panels[panelName];
  47072. var hadCurrentQuery = !!panel.currentQuery;
  47073. delete panel.currentQuery;
  47074. if (hadCurrentQuery)
  47075. panel.searchCanceled();
  47076. }
  47077. this._updateSearchMatchesCountAndCurrentMatchIndex(0, -1);
  47078. return;
  47079. }
  47080.  
  47081. var currentPanel = WebInspector.inspectorView.currentPanel();
  47082. if (query === currentPanel.currentQuery && currentPanel.currentQuery === this._currentQuery) {
  47083.  
  47084.  
  47085. if (forceSearch) {
  47086. if (!isBackwardSearch)
  47087. currentPanel.jumpToNextSearchResult();
  47088. else if (isBackwardSearch)
  47089. currentPanel.jumpToPreviousSearchResult();
  47090. }
  47091. return;
  47092. }
  47093.  
  47094. if (!forceSearch && query.length < 3 && !this._currentQuery)
  47095. return;
  47096.  
  47097. this._currentQuery = query;
  47098.  
  47099. currentPanel.currentQuery = query;
  47100. currentPanel.performSearch(query);
  47101. },
  47102.  
  47103. _updateSecondRowVisibility: function()
  47104. {
  47105. if (!this._searchIsVisible)
  47106. return;
  47107. if (this._replaceCheckboxElement.checked) {
  47108. this._element.addStyleClass("toolbar-search-replace");
  47109. this._secondRowElement.removeStyleClass("hidden");
  47110. this._prevButtonElement.removeStyleClass("hidden");
  47111. this._findButtonElement.removeStyleClass("hidden");
  47112. this._replaceCheckboxElement.tabIndex = -1;
  47113. this._replaceInputElement.focus();
  47114. } else {
  47115. this._element.removeStyleClass("toolbar-search-replace");
  47116. this._secondRowElement.addStyleClass("hidden");
  47117. this._prevButtonElement.addStyleClass("hidden");
  47118. this._findButtonElement.addStyleClass("hidden");
  47119. this._replaceCheckboxElement.tabIndex = 0;
  47120. this._searchInputElement.focus();
  47121. }
  47122. WebInspector.inspectorView.setFooterElement(this._element);
  47123. },
  47124.  
  47125. _replace: function()
  47126. {
  47127. var currentPanel = WebInspector.inspectorView.currentPanel();
  47128. currentPanel.replaceSelectionWith(this._replaceInputElement.value);
  47129. var query = this._currentQuery;
  47130. delete this._currentQuery;
  47131. this._performSearch(query, true, false);
  47132. },
  47133.  
  47134. _replaceAll: function()
  47135. {
  47136. var currentPanel = WebInspector.inspectorView.currentPanel();
  47137. currentPanel.replaceAllWith(this._searchInputElement.value, this._replaceInputElement.value);
  47138. },
  47139.  
  47140. _filterCheckboxClick: function()
  47141. {
  47142. if (this._filterCheckboxElement.checked) { 
  47143. this._switchSearchToFilter();
  47144. this._performFilter(this._filterInputElement.value);
  47145. } else {
  47146. this._switchFilterToSearch();
  47147. this._performSearch(this._searchInputElement.value, false, false);
  47148. }
  47149. },
  47150.  
  47151.  
  47152. _performFilter: function(query)
  47153. {
  47154. WebInspector.inspectorView.currentPanel().performFilter(query);
  47155. },
  47156.  
  47157. _onFilterInput: function(event)
  47158. {
  47159. this._performFilter(event.target.value);
  47160. },
  47161.  
  47162. _onSearchInput: function(event)
  47163. {
  47164. this._performSearch(event.target.value, false, false);
  47165. },
  47166.  
  47167. resetFilter: function()
  47168. {
  47169. this._performFilter("");
  47170. }
  47171. }
  47172.  
  47173.  
  47174. WebInspector.searchController = null;
  47175.  
  47176.  
  47177.  
  47178.  
  47179.  
  47180.  
  47181. WebInspector.WorkerManager = function()
  47182. {
  47183. this._workerIdToWindow = {};
  47184. InspectorBackend.registerWorkerDispatcher(new WebInspector.WorkerDispatcher(this));
  47185. }
  47186.  
  47187. WebInspector.WorkerManager.isWorkerFrontend = function()
  47188. {
  47189. return !!WebInspector.queryParamsObject["dedicatedWorkerId"] ||
  47190. !!WebInspector.queryParamsObject["isSharedWorker"];
  47191. }
  47192.  
  47193. WebInspector.WorkerManager.isDedicatedWorkerFrontend = function()
  47194. {
  47195. return !!WebInspector.queryParamsObject["dedicatedWorkerId"];
  47196. }
  47197.  
  47198. WebInspector.WorkerManager.loaded = function()
  47199. {
  47200. var workerId = WebInspector.queryParamsObject["dedicatedWorkerId"];
  47201. if (workerId)
  47202. WebInspector.WorkerManager._initializeDedicatedWorkerFrontend(workerId);
  47203. else
  47204. WebInspector.workerManager = new WebInspector.WorkerManager();
  47205. }
  47206.  
  47207. WebInspector.WorkerManager.loadCompleted = function()
  47208. {
  47209.  
  47210.  
  47211. if (WebInspector.queryParamsObject["workerPaused"]) {
  47212. DebuggerAgent.pause();
  47213. RuntimeAgent.run(calculateTitle);
  47214. } else if (WebInspector.WorkerManager.isWorkerFrontend())
  47215. calculateTitle();
  47216.  
  47217. function calculateTitle()
  47218. {
  47219. WebInspector.WorkerManager._calculateWorkerInspectorTitle();
  47220. }
  47221.  
  47222. if (WebInspector.workerManager)
  47223. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.MainFrameNavigated, WebInspector.workerManager._mainFrameNavigated, WebInspector.workerManager);
  47224. }
  47225.  
  47226. WebInspector.WorkerManager._initializeDedicatedWorkerFrontend = function(workerId)
  47227. {
  47228. function receiveMessage(event)
  47229. {
  47230. var message = event.data;
  47231. InspectorBackend.dispatch(message);
  47232. }
  47233. window.addEventListener("message", receiveMessage, true);
  47234.  
  47235.  
  47236. InspectorBackend.sendMessageObjectToBackend = function(message)
  47237. {
  47238. window.opener.postMessage({workerId: workerId, command: "sendMessageToBackend", message: message}, "*");
  47239. }
  47240.  
  47241. InspectorFrontendHost.loaded = function()
  47242. {
  47243. window.opener.postMessage({workerId: workerId, command: "loaded"}, "*");
  47244. }
  47245. }
  47246.  
  47247. WebInspector.WorkerManager._calculateWorkerInspectorTitle = function()
  47248. {
  47249. var expression = "location.href";
  47250. if (WebInspector.queryParamsObject["isSharedWorker"])
  47251. expression += " + (this.name ? ' (' + this.name + ')' : '')";
  47252. RuntimeAgent.evaluate.invoke({expression:expression, doNotPauseOnExceptionsAndMuteConsole:true, returnByValue: true}, evalCallback.bind(this));
  47253.  
  47254.  
  47255. function evalCallback(error, result, wasThrown)
  47256. {
  47257. if (error || wasThrown) {
  47258. console.error(error);
  47259. return;
  47260. }
  47261. InspectorFrontendHost.inspectedURLChanged(result.value);
  47262. }
  47263. }
  47264.  
  47265. WebInspector.WorkerManager.Events = {
  47266. WorkerAdded: "worker-added",
  47267. WorkerRemoved: "worker-removed",
  47268. WorkersCleared: "workers-cleared",
  47269. }
  47270.  
  47271. WebInspector.WorkerManager.prototype = {
  47272. _workerCreated: function(workerId, url, inspectorConnected)
  47273. {
  47274. if (inspectorConnected)
  47275. this._openInspectorWindow(workerId, true);
  47276. this.dispatchEventToListeners(WebInspector.WorkerManager.Events.WorkerAdded, {workerId: workerId, url: url, inspectorConnected: inspectorConnected});
  47277. },
  47278.  
  47279. _workerTerminated: function(workerId)
  47280. {
  47281. this.closeWorkerInspector(workerId);
  47282. this.dispatchEventToListeners(WebInspector.WorkerManager.Events.WorkerRemoved, workerId);
  47283. },
  47284.  
  47285. _sendMessageToWorkerInspector: function(workerId, message)
  47286. {
  47287. var workerInspectorWindow = this._workerIdToWindow[workerId];
  47288. if (workerInspectorWindow)
  47289. workerInspectorWindow.postMessage(message, "*");
  47290. },
  47291.  
  47292. openWorkerInspector: function(workerId)
  47293. {
  47294. var existingInspector = this._workerIdToWindow[workerId];
  47295. if (existingInspector) {
  47296. existingInspector.focus();
  47297. return;
  47298. }
  47299.  
  47300. this._openInspectorWindow(workerId, false);
  47301. WorkerAgent.connectToWorker(workerId);
  47302. },
  47303.  
  47304. _openInspectorWindow: function(workerId, workerIsPaused)
  47305. {
  47306. var search = window.location.search;
  47307. var hash = window.location.hash;
  47308. var url = window.location.href;
  47309.  
  47310. url = url.replace(hash, "");
  47311. url += (search ? "&dedicatedWorkerId=" : "?dedicatedWorkerId=") + workerId;
  47312. if (workerIsPaused)
  47313. url += "&workerPaused=true";
  47314. url = url.replace("docked=true&", "");
  47315. url += hash;
  47316.  
  47317. var workerInspectorWindow = window.open(url, undefined, "location=0");
  47318. this._workerIdToWindow[workerId] = workerInspectorWindow;
  47319. workerInspectorWindow.addEventListener("beforeunload", this._workerInspectorClosing.bind(this, workerId), true);
  47320.  
  47321.  
  47322. window.addEventListener("beforeunload", this._pageInspectorClosing.bind(this), true);
  47323. WebInspector.notifications.addEventListener(WebInspector.Events.InspectorClosing, this._pageInspectorClosing, this);
  47324. },
  47325.  
  47326. closeWorkerInspector: function(workerId)
  47327. {
  47328. var workerInspectorWindow = this._workerIdToWindow[workerId];
  47329. if (workerInspectorWindow)
  47330. workerInspectorWindow.close();
  47331. },
  47332.  
  47333. _mainFrameNavigated: function(event)
  47334. {
  47335. for (var workerId in this._workerIdToWindow)
  47336. this.closeWorkerInspector(workerId);
  47337. this.dispatchEventToListeners(WebInspector.WorkerManager.Events.WorkersCleared);
  47338. },
  47339.  
  47340. _pageInspectorClosing: function()
  47341. {
  47342. this._ignoreWorkerInspectorClosing = true;
  47343. for (var workerId in this._workerIdToWindow) {
  47344. this._workerIdToWindow[workerId].close();
  47345. WorkerAgent.disconnectFromWorker(parseInt(workerId, 10));
  47346. }
  47347. },
  47348.  
  47349. _workerInspectorClosing: function(workerId, event)
  47350. {
  47351. if (event.target.location.href === "about:blank")
  47352. return;
  47353. if (this._ignoreWorkerInspectorClosing)
  47354. return;
  47355. delete this._workerIdToWindow[workerId];
  47356. WorkerAgent.disconnectFromWorker(workerId);
  47357. },
  47358.  
  47359. _disconnectedFromWorker: function()
  47360. {
  47361. var screen = new WebInspector.WorkerTerminatedScreen();
  47362. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjectCleared, screen.hide, screen);
  47363. screen.showModal();
  47364. },
  47365.  
  47366. __proto__: WebInspector.Object.prototype
  47367. }
  47368.  
  47369.  
  47370. WebInspector.WorkerDispatcher = function(workerManager)
  47371. {
  47372. this._workerManager = workerManager;
  47373. window.addEventListener("message", this._receiveMessage.bind(this), true);
  47374. }
  47375.  
  47376. WebInspector.WorkerDispatcher.prototype = {
  47377. _receiveMessage: function(event)
  47378. {
  47379. var workerId = event.data["workerId"];
  47380. workerId = parseInt(workerId, 10);
  47381. var command = event.data.command;
  47382. var message = event.data.message;
  47383.  
  47384. if (command == "sendMessageToBackend")
  47385. WorkerAgent.sendMessageToWorker(workerId, message);
  47386. },
  47387.  
  47388. workerCreated: function(workerId, url, inspectorConnected)
  47389. {
  47390. this._workerManager._workerCreated(workerId, url, inspectorConnected);
  47391. },
  47392.  
  47393. workerTerminated: function(workerId)
  47394. {
  47395. this._workerManager._workerTerminated(workerId);
  47396. },
  47397.  
  47398. dispatchMessageFromWorker: function(workerId, message)
  47399. {
  47400. this._workerManager._sendMessageToWorkerInspector(workerId, message);
  47401. },
  47402.  
  47403. disconnectedFromWorker: function()
  47404. {
  47405. this._workerManager._disconnectedFromWorker();
  47406. }
  47407. }
  47408.  
  47409.  
  47410. WebInspector.WorkerTerminatedScreen = function()
  47411. {
  47412. WebInspector.HelpScreen.call(this, WebInspector.UIString("Inspected worker terminated"));
  47413. var p = this.contentElement.createChild("p");
  47414. p.addStyleClass("help-section");
  47415. p.textContent = WebInspector.UIString("Inspected worker has terminated. Once it restarts we will attach to it automatically.");
  47416. }
  47417.  
  47418. WebInspector.WorkerTerminatedScreen.prototype = {
  47419.  
  47420. willHide: function()
  47421. {
  47422. WebInspector.debuggerModel.removeEventListener(WebInspector.DebuggerModel.Events.GlobalObjectCleared, this.hide, this);
  47423. WebInspector.HelpScreen.prototype.willHide.call(this);
  47424. },
  47425.  
  47426. __proto__: WebInspector.HelpScreen.prototype
  47427. }
  47428.  
  47429.  
  47430.  
  47431.  
  47432.  
  47433.  
  47434. WebInspector.UserMetrics = function()
  47435. {
  47436. for (var actionName in WebInspector.UserMetrics._ActionCodes) {
  47437. var actionCode = WebInspector.UserMetrics._ActionCodes[actionName];
  47438. this[actionName] = new WebInspector.UserMetrics._Recorder(actionCode);
  47439. }
  47440.  
  47441. function settingChanged(trueCode, falseCode, event)
  47442. {
  47443. if (event.data)
  47444. InspectorFrontendHost.recordSettingChanged(trueCode);
  47445. else
  47446. InspectorFrontendHost.recordSettingChanged(falseCode);
  47447. }
  47448.  
  47449. WebInspector.settings.domWordWrap.addChangeListener(settingChanged.bind(this, WebInspector.UserMetrics._SettingCodes.ElementsDOMWrapOn, WebInspector.UserMetrics._SettingCodes.ElementsDOMWrapOff));
  47450. WebInspector.settings.monitoringXHREnabled.addChangeListener(settingChanged.bind(this, WebInspector.UserMetrics._SettingCodes.ConsoleMonitorXHROn, WebInspector.UserMetrics._SettingCodes.ConsoleMonitorXHROff));
  47451. WebInspector.settings.preserveConsoleLog.addChangeListener(settingChanged.bind(this, WebInspector.UserMetrics._SettingCodes.ConsolePreserveLogOn, WebInspector.UserMetrics._SettingCodes.ConsolePreserveLogOff));
  47452. WebInspector.settings.resourcesLargeRows.addChangeListener(settingChanged.bind(this, WebInspector.UserMetrics._SettingCodes.NetworkShowLargeRowsOn, WebInspector.UserMetrics._SettingCodes.NetworkShowLargeRowsOff));
  47453. }
  47454.  
  47455.  
  47456.  
  47457.  
  47458.  
  47459. WebInspector.UserMetrics._ActionCodes = {
  47460. WindowDocked: 1,
  47461. WindowUndocked: 2,
  47462. ScriptsBreakpointSet: 3,
  47463. TimelineStarted: 4,
  47464. ProfilesCPUProfileTaken: 5,
  47465. ProfilesHeapProfileTaken: 6,
  47466. AuditsStarted: 7,
  47467. ConsoleEvaluated: 8
  47468. }
  47469.  
  47470. WebInspector.UserMetrics._SettingCodes = {
  47471. ElementsDOMWrapOn: 1,
  47472. ElementsDOMWrapOff: 2,
  47473. ConsoleMonitorXHROn: 3,
  47474. ConsoleMonitorXHROff: 4,
  47475. ConsolePreserveLogOn: 5,
  47476. ConsolePreserveLogOff: 6,
  47477. NetworkShowLargeRowsOn: 7,
  47478. NetworkShowLargeRowsOff: 8
  47479. }
  47480.  
  47481. WebInspector.UserMetrics._PanelCodes = {
  47482. elements: 1,
  47483. resources: 2,
  47484. network: 3,
  47485. scripts: 4,
  47486. timeline: 5,
  47487. profiles: 6,
  47488. audits: 7,
  47489. console: 8
  47490. }
  47491.  
  47492. WebInspector.UserMetrics.UserAction = "UserAction";
  47493.  
  47494. WebInspector.UserMetrics.UserActionNames = {
  47495. ForcedElementState: "forcedElementState",
  47496. FileSaved: "fileSaved",
  47497. RevertRevision: "revertRevision",
  47498. ApplyOriginalContent: "applyOriginalContent",
  47499. TogglePrettyPrint: "togglePrettyPrint",
  47500. SetBreakpoint: "setBreakpoint",
  47501. OpenSourceLink: "openSourceLink",
  47502. NetworkSort: "networkSort",
  47503. NetworkRequestSelected: "networkRequestSelected",
  47504. NetworkRequestTabSelected: "networkRequestTabSelected",
  47505. HeapSnapshotFilterChanged: "heapSnapshotFilterChanged"
  47506. };
  47507.  
  47508. WebInspector.UserMetrics.prototype = {
  47509. panelShown: function(panelName)
  47510. {
  47511. InspectorFrontendHost.recordPanelShown(WebInspector.UserMetrics._PanelCodes[panelName] || 0);
  47512. }
  47513. }
  47514.  
  47515.  
  47516. WebInspector.UserMetrics._Recorder = function(actionCode)
  47517. {
  47518. this._actionCode = actionCode;
  47519. }
  47520.  
  47521. WebInspector.UserMetrics._Recorder.prototype = {
  47522. record: function()
  47523. {
  47524. InspectorFrontendHost.recordActionTaken(this._actionCode);
  47525. }
  47526. }
  47527.  
  47528. WebInspector.userMetrics = new WebInspector.UserMetrics();
  47529.  
  47530.  
  47531.  
  47532.  
  47533.  
  47534.  
  47535. WebInspector.RuntimeModel = function(resourceTreeModel)
  47536. {
  47537. resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameAdded, this._frameAdded, this);
  47538. resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameNavigated, this._frameNavigated, this);
  47539. resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameDetached, this._frameDetached, this);
  47540. resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.CachedResourcesLoaded, this._didLoadCachedResources, this);
  47541. this._frameIdToContextList = {};
  47542. }
  47543.  
  47544. WebInspector.RuntimeModel.Events = {
  47545. FrameExecutionContextListAdded: "FrameExecutionContextListAdded",
  47546. FrameExecutionContextListRemoved: "FrameExecutionContextListRemoved",
  47547. }
  47548.  
  47549. WebInspector.RuntimeModel.prototype = {
  47550.  
  47551. setCurrentExecutionContext: function(executionContext)
  47552. {
  47553. this._currentExecutionContext = executionContext;
  47554. },
  47555.  
  47556.  
  47557. currentExecutionContext: function()
  47558. {
  47559. return this._currentExecutionContext;
  47560. },
  47561.  
  47562.  
  47563. contextLists: function()
  47564. {
  47565. return Object.values(this._frameIdToContextList);
  47566. },
  47567.  
  47568.  
  47569. contextByFrameAndSecurityOrigin: function(frame, securityOrigin)
  47570. {
  47571. var frameContext = this._frameIdToContextList[frame.id];
  47572. return frameContext && frameContext.contextBySecurityOrigin(securityOrigin);
  47573. },
  47574.  
  47575. _frameAdded: function(event)
  47576. {
  47577. var frame = event.data;
  47578. var context = new WebInspector.FrameExecutionContextList(frame);
  47579. this._frameIdToContextList[frame.id] = context;
  47580. this.dispatchEventToListeners(WebInspector.RuntimeModel.Events.FrameExecutionContextListAdded, context);
  47581. },
  47582.  
  47583. _frameNavigated: function(event)
  47584. {
  47585. var frame = event.data;
  47586. var context = this._frameIdToContextList[frame.id];
  47587. if (context)
  47588. context._frameNavigated(frame);
  47589. },
  47590.  
  47591. _frameDetached: function(event)
  47592. {
  47593. var frame = event.data;
  47594. var context = this._frameIdToContextList[frame.id];
  47595. if (!context)
  47596. return;
  47597. this.dispatchEventToListeners(WebInspector.RuntimeModel.Events.FrameExecutionContextListRemoved, context);
  47598. delete this._frameIdToContextList[frame.id];
  47599. },
  47600.  
  47601. _didLoadCachedResources: function()
  47602. {
  47603. InspectorBackend.registerRuntimeDispatcher(new WebInspector.RuntimeDispatcher(this));
  47604. RuntimeAgent.enable();
  47605. },
  47606.  
  47607. _executionContextCreated: function(context)
  47608. {
  47609. var contextList = this._frameIdToContextList[context.frameId];
  47610.  
  47611. if (!contextList)
  47612. return;
  47613. contextList._addExecutionContext(new WebInspector.ExecutionContext(context.id, context.name, context.isPageContext));
  47614. },
  47615.  
  47616.  
  47617. evaluate: function(expression, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, callback)
  47618. {
  47619. if (WebInspector.debuggerModel.selectedCallFrame()) {
  47620. WebInspector.debuggerModel.evaluateOnSelectedCallFrame(expression, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, returnByValue, generatePreview, callback);
  47621. return;
  47622. }
  47623.  
  47624. if (!expression) {
  47625.  
  47626. expression = "this";
  47627. }
  47628.  
  47629.  
  47630. function evalCallback(error, result, wasThrown)
  47631. {
  47632. if (error) {
  47633. console.error(error);
  47634. callback(null, false);
  47635. return;
  47636. }
  47637.  
  47638. if (returnByValue)
  47639. callback(null, !!wasThrown, wasThrown ? null : result);
  47640. else
  47641. callback(WebInspector.RemoteObject.fromPayload(result), !!wasThrown);
  47642. }
  47643. RuntimeAgent.evaluate(expression, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, this._currentExecutionContext ? this._currentExecutionContext.id : undefined, returnByValue, generatePreview, evalCallback);
  47644. },
  47645.  
  47646.  
  47647. completionsForTextPrompt: function(proxyElement, wordRange, force, completionsReadyCallback)
  47648. {
  47649.  
  47650. var expressionRange = wordRange.startContainer.rangeOfWord(wordRange.startOffset, " =:[({;,!+-*/&|^<>", proxyElement, "backward");
  47651. var expressionString = expressionRange.toString();
  47652. var prefix = wordRange.toString();
  47653. this._completionsForExpression(expressionString, prefix, force, completionsReadyCallback);
  47654. },
  47655.  
  47656.  
  47657. _completionsForExpression: function(expressionString, prefix, force, completionsReadyCallback)
  47658. {
  47659. var lastIndex = expressionString.length - 1;
  47660.  
  47661. var dotNotation = (expressionString[lastIndex] === ".");
  47662. var bracketNotation = (expressionString[lastIndex] === "[");
  47663.  
  47664. if (dotNotation || bracketNotation)
  47665. expressionString = expressionString.substr(0, lastIndex);
  47666.  
  47667. if (expressionString && parseInt(expressionString, 10) == expressionString) {
  47668.  
  47669. completionsReadyCallback([]);
  47670. return;
  47671. }
  47672.  
  47673. if (!prefix && !expressionString && !force) {
  47674. completionsReadyCallback([]);
  47675. return;
  47676. }
  47677.  
  47678. if (!expressionString && WebInspector.debuggerModel.selectedCallFrame())
  47679. WebInspector.debuggerModel.getSelectedCallFrameVariables(receivedPropertyNames.bind(this));
  47680. else
  47681. this.evaluate(expressionString, "completion", true, true, false, false, evaluated.bind(this));
  47682.  
  47683. function evaluated(result, wasThrown)
  47684. {
  47685. if (!result || wasThrown) {
  47686. completionsReadyCallback([]);
  47687. return;
  47688. }
  47689.  
  47690. function getCompletions(primitiveType)
  47691. {
  47692. var object;
  47693. if (primitiveType === "string")
  47694. object = new String("");
  47695. else if (primitiveType === "number")
  47696. object = new Number(0);
  47697. else if (primitiveType === "boolean")
  47698. object = new Boolean(false);
  47699. else
  47700. object = this;
  47701.  
  47702. var resultSet = {};
  47703. for (var o = object; o; o = o.__proto__) {
  47704. try {
  47705. var names = Object.getOwnPropertyNames(o);
  47706. for (var i = 0; i < names.length; ++i)
  47707. resultSet[names[i]] = true;
  47708. } catch (e) {
  47709. }
  47710. }
  47711. return resultSet;
  47712. }
  47713.  
  47714. if (result.type === "object" || result.type === "function")
  47715. result.callFunctionJSON(getCompletions, undefined, receivedPropertyNames.bind(this));
  47716. else if (result.type === "string" || result.type === "number" || result.type === "boolean")
  47717. this.evaluate("(" + getCompletions + ")(\"" + result.type + "\")", "completion", false, true, true, false, receivedPropertyNamesFromEval.bind(this));
  47718. }
  47719.  
  47720. function receivedPropertyNamesFromEval(notRelevant, wasThrown, result)
  47721. {
  47722. if (result && !wasThrown)
  47723. receivedPropertyNames.call(this, result.value);
  47724. else
  47725. completionsReadyCallback([]);
  47726. }
  47727.  
  47728. function receivedPropertyNames(propertyNames)
  47729. {
  47730. RuntimeAgent.releaseObjectGroup("completion");
  47731. if (!propertyNames) {
  47732. completionsReadyCallback([]);
  47733. return;
  47734. }
  47735. var includeCommandLineAPI = (!dotNotation && !bracketNotation);
  47736. if (includeCommandLineAPI) {
  47737. const commandLineAPI = ["dir", "dirxml", "keys", "values", "profile", "profileEnd", "monitorEvents", "unmonitorEvents", "inspect", "copy", "clear"];
  47738. for (var i = 0; i < commandLineAPI.length; ++i)
  47739. propertyNames[commandLineAPI[i]] = true;
  47740. }
  47741. this._reportCompletions(completionsReadyCallback, dotNotation, bracketNotation, expressionString, prefix, Object.keys(propertyNames));
  47742. }
  47743. },
  47744.  
  47745.  
  47746. _reportCompletions: function(completionsReadyCallback, dotNotation, bracketNotation, expressionString, prefix, properties) {
  47747. if (bracketNotation) {
  47748. if (prefix.length && prefix[0] === "'")
  47749. var quoteUsed = "'";
  47750. else
  47751. var quoteUsed = "\"";
  47752. }
  47753.  
  47754. var results = [];
  47755.  
  47756. if (!expressionString) {
  47757. const keywords = ["break", "case", "catch", "continue", "default", "delete", "do", "else", "finally", "for", "function", "if", "in",
  47758. "instanceof", "new", "return", "switch", "this", "throw", "try", "typeof", "var", "void", "while", "with"];
  47759. properties = properties.concat(keywords);
  47760. }
  47761.  
  47762. properties.sort();
  47763.  
  47764. for (var i = 0; i < properties.length; ++i) {
  47765. var property = properties[i];
  47766.  
  47767. if (dotNotation && !/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(property))
  47768. continue;
  47769.  
  47770. if (bracketNotation) {
  47771. if (!/^[0-9]+$/.test(property))
  47772. property = quoteUsed + property.escapeCharacters(quoteUsed + "\\") + quoteUsed;
  47773. property += "]";
  47774. }
  47775.  
  47776. if (property.length < prefix.length)
  47777. continue;
  47778. if (prefix.length && !property.startsWith(prefix))
  47779. continue;
  47780.  
  47781. results.push(property);
  47782. }
  47783. completionsReadyCallback(results);
  47784. },
  47785.  
  47786. __proto__: WebInspector.Object.prototype
  47787. }
  47788.  
  47789.  
  47790. WebInspector.runtimeModel = null;
  47791.  
  47792.  
  47793. WebInspector.RuntimeDispatcher = function(runtimeModel)
  47794. {
  47795. this._runtimeModel = runtimeModel;
  47796. }
  47797.  
  47798. WebInspector.RuntimeDispatcher.prototype = {
  47799. executionContextCreated: function(context)
  47800. {
  47801. this._runtimeModel._executionContextCreated(context);
  47802. }
  47803. }
  47804.  
  47805.  
  47806. WebInspector.ExecutionContext = function(id, name, isPageContext)
  47807. {
  47808. this.id = id;
  47809. this.name = (isPageContext && !name) ? "<page context>" : name;
  47810. this.isMainWorldContext = isPageContext;
  47811. }
  47812.  
  47813.  
  47814. WebInspector.ExecutionContext.comparator = function(a, b)
  47815. {
  47816.  
  47817. if (a.isMainWorldContext)
  47818. return -1;
  47819. if (b.isMainWorldContext)
  47820. return +1;
  47821. return a.name.localeCompare(b.name);
  47822. }
  47823.  
  47824.  
  47825. WebInspector.FrameExecutionContextList = function(frame)
  47826. {
  47827. this._frame = frame;
  47828. this._executionContexts = [];
  47829. }
  47830.  
  47831. WebInspector.FrameExecutionContextList.EventTypes = {
  47832. ContextsUpdated: "ContextsUpdated",
  47833. ContextAdded: "ContextAdded"
  47834. }
  47835.  
  47836. WebInspector.FrameExecutionContextList.prototype =
  47837. {
  47838. _frameNavigated: function(frame)
  47839. {
  47840. this._frame = frame;
  47841. this._executionContexts = [];
  47842. this.dispatchEventToListeners(WebInspector.FrameExecutionContextList.EventTypes.ContextsUpdated, this);
  47843. },
  47844.  
  47845.  
  47846. _addExecutionContext: function(context)
  47847. {
  47848. var insertAt = insertionIndexForObjectInListSortedByFunction(context, this._executionContexts, WebInspector.ExecutionContext.comparator);
  47849. this._executionContexts.splice(insertAt, 0, context);
  47850. this.dispatchEventToListeners(WebInspector.FrameExecutionContextList.EventTypes.ContextAdded, this);
  47851. },
  47852.  
  47853. executionContexts: function()
  47854. {
  47855. return this._executionContexts;
  47856. },
  47857.  
  47858.  
  47859. contextBySecurityOrigin: function(securityOrigin)
  47860. {
  47861. for (var i = 0; i < this._executionContexts.length; ++i) {
  47862. var context = this._executionContexts[i];
  47863. if (!context.isMainWorldContext && context.name === securityOrigin)
  47864. return context; 
  47865. }
  47866. },
  47867.  
  47868. get frameId()
  47869. {
  47870. return this._frame.id;
  47871. },
  47872.  
  47873. get url()
  47874. {
  47875. return this._frame.url;
  47876. },
  47877.  
  47878. get displayName()
  47879. {
  47880. if (!this._frame.parentFrame)
  47881. return "<top frame>";
  47882. var name = this._frame.name || "";
  47883. var subtitle = new WebInspector.ParsedURL(this._frame.url).displayName;
  47884. if (subtitle) {
  47885. if (!name)
  47886. return subtitle;
  47887. return name + "( " + subtitle + " )";
  47888. }
  47889. return "<iframe>";
  47890. },
  47891.  
  47892. __proto__: WebInspector.Object.prototype
  47893. }
  47894.  
  47895.  
  47896.  
  47897.  
  47898.  
  47899.  
  47900. WebInspector.HandlerRegistry = function(setting)
  47901. {
  47902. WebInspector.Object.call(this);
  47903. this._handlers = {};
  47904. this._setting = setting;
  47905. this._activeHandler = this._setting.get();
  47906. WebInspector.ContextMenu.registerProvider(this);
  47907. }
  47908.  
  47909. WebInspector.HandlerRegistry.prototype = {
  47910. get handlerNames()
  47911. {
  47912. return Object.getOwnPropertyNames(this._handlers);
  47913. },
  47914.  
  47915. get activeHandler()
  47916. {
  47917. return this._activeHandler;
  47918. },
  47919.  
  47920. set activeHandler(value)
  47921. {
  47922. this._activeHandler = value;
  47923. this._setting.set(value);
  47924. },
  47925.  
  47926.  
  47927. dispatch: function(data)
  47928. {
  47929. return this.dispatchToHandler(this._activeHandler, data);
  47930. },
  47931.  
  47932.  
  47933. dispatchToHandler: function(name, data)
  47934. {
  47935. var handler = this._handlers[name];
  47936. var result = handler && handler(data);
  47937. return !!result;
  47938. },
  47939.  
  47940. registerHandler: function(name, handler)
  47941. {
  47942. this._handlers[name] = handler;
  47943. this.dispatchEventToListeners(WebInspector.HandlerRegistry.EventTypes.HandlersUpdated);
  47944. },
  47945.  
  47946. unregisterHandler: function(name)
  47947. {
  47948. delete this._handlers[name];
  47949. this.dispatchEventToListeners(WebInspector.HandlerRegistry.EventTypes.HandlersUpdated);
  47950. },
  47951.  
  47952.  
  47953. appendApplicableItems: function(event, contextMenu, target)
  47954. {
  47955. if (event.hasBeenHandledByHandlerRegistry)
  47956. return;
  47957. event.hasBeenHandledByHandlerRegistry = true;
  47958. this._appendContentProviderItems(contextMenu, target);
  47959. this._appendHrefItems(contextMenu, target);
  47960. },
  47961.  
  47962.  
  47963. _appendContentProviderItems: function(contextMenu, target)
  47964. {
  47965. if (!(target instanceof WebInspector.UISourceCode || target instanceof WebInspector.Resource || target instanceof WebInspector.NetworkRequest))
  47966. return;
  47967. var contentProvider =   (target);
  47968. if (!contentProvider.contentURL())
  47969. return;
  47970.  
  47971. contextMenu.appendItem(WebInspector.openLinkExternallyLabel(), WebInspector.openResource.bind(WebInspector, contentProvider.contentURL(), false));
  47972.  
  47973. for (var i = 1; i < this.handlerNames.length; ++i) {
  47974. var handler = this.handlerNames[i];
  47975. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Open using %s" : "Open Using %s", handler),
  47976. this.dispatchToHandler.bind(this, handler, { url: contentProvider.contentURL() }));
  47977. }
  47978. contextMenu.appendItem(WebInspector.copyLinkAddressLabel(), InspectorFrontendHost.copyText.bind(InspectorFrontendHost, contentProvider.contentURL()));
  47979.  
  47980. if (!InspectorFrontendHost.canSave() || !contentProvider.contentURL())
  47981. return;
  47982.  
  47983. var contentType = contentProvider.contentType();
  47984. if (contentType !== WebInspector.resourceTypes.Document &&
  47985. contentType !== WebInspector.resourceTypes.Stylesheet &&
  47986. contentType !== WebInspector.resourceTypes.Script)
  47987. return;
  47988.  
  47989. function doSave(forceSaveAs, content)
  47990. {
  47991. var url = contentProvider.contentURL();
  47992. WebInspector.fileManager.save(url, content, forceSaveAs);
  47993. WebInspector.fileManager.close(url);
  47994. }
  47995.  
  47996. function save(forceSaveAs)
  47997. {
  47998. if (contentProvider instanceof WebInspector.UISourceCode) {
  47999. var uiSourceCode =   (contentProvider);
  48000. if (uiSourceCode.isDirty()) {
  48001. doSave(forceSaveAs, uiSourceCode.workingCopy());
  48002. uiSourceCode.commitWorkingCopy(function() { });
  48003. return;
  48004. }
  48005. }
  48006. contentProvider.requestContent(doSave.bind(this, forceSaveAs));
  48007. }
  48008.  
  48009. contextMenu.appendSeparator();
  48010. contextMenu.appendItem(WebInspector.UIString("Save"), save.bind(this, false));
  48011. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Save as..." : "Save As..."), save.bind(this, true));
  48012. },
  48013.  
  48014.  
  48015. _appendHrefItems: function(contextMenu, target)
  48016. {
  48017. if (!(target instanceof Node))
  48018. return;
  48019. var targetNode =   (target);
  48020.  
  48021. var anchorElement = targetNode.enclosingNodeOrSelfWithClass("webkit-html-resource-link") || targetNode.enclosingNodeOrSelfWithClass("webkit-html-external-link");
  48022. if (!anchorElement)
  48023. return;
  48024.  
  48025. var resourceURL = anchorElement.href;
  48026. if (!resourceURL)
  48027. return;
  48028.  
  48029.  
  48030. contextMenu.appendItem(WebInspector.openLinkExternallyLabel(), WebInspector.openResource.bind(WebInspector, resourceURL, false));
  48031. if (WebInspector.resourceForURL(resourceURL))
  48032. contextMenu.appendItem(WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Open link in Resources panel" : "Open Link in Resources Panel"), WebInspector.openResource.bind(null, resourceURL, true));
  48033. contextMenu.appendItem(WebInspector.copyLinkAddressLabel(), InspectorFrontendHost.copyText.bind(InspectorFrontendHost, resourceURL));
  48034. },
  48035.  
  48036. __proto__: WebInspector.Object.prototype
  48037. }
  48038.  
  48039.  
  48040. WebInspector.HandlerRegistry.EventTypes = {
  48041. HandlersUpdated: "HandlersUpdated"
  48042. }
  48043.  
  48044.  
  48045. WebInspector.HandlerSelector = function(handlerRegistry)
  48046. {
  48047. this._handlerRegistry = handlerRegistry;
  48048. this.element = document.createElement("select");
  48049. this.element.addEventListener("change", this._onChange.bind(this), false);
  48050. this._update();
  48051. this._handlerRegistry.addEventListener(WebInspector.HandlerRegistry.EventTypes.HandlersUpdated, this._update.bind(this));
  48052. }
  48053.  
  48054. WebInspector.HandlerSelector.prototype =
  48055. {
  48056. _update: function()
  48057. {
  48058. this.element.removeChildren();
  48059. var names = this._handlerRegistry.handlerNames;
  48060. var activeHandler = this._handlerRegistry.activeHandler;
  48061.  
  48062. for (var i = 0; i < names.length; ++i) {
  48063. var option = document.createElement("option");
  48064. option.textContent = names[i];
  48065. option.selected = activeHandler === names[i];
  48066. this.element.appendChild(option);
  48067. }
  48068. this.element.disabled = names.length <= 1;
  48069. },
  48070.  
  48071. _onChange: function(event)
  48072. {
  48073. var value = event.target.value;
  48074. this._handlerRegistry.activeHandler = value;
  48075. }
  48076. }
  48077.  
  48078.  
  48079.  
  48080. WebInspector.openAnchorLocationRegistry = null;
  48081.  
  48082.  
  48083.  
  48084.  
  48085.  
  48086.  
  48087. WebInspector.SnippetStorage = function(settingPrefix, namePrefix)
  48088. {
  48089. this._snippets = {};
  48090.  
  48091. this._lastSnippetIdentifierSetting = WebInspector.settings.createSetting(settingPrefix + "Snippets_lastIdentifier", 0);
  48092. this._snippetsSetting = WebInspector.settings.createSetting(settingPrefix + "Snippets", []);
  48093. this._namePrefix = namePrefix;
  48094.  
  48095. this._loadSettings();
  48096. }
  48097.  
  48098. WebInspector.SnippetStorage.prototype = {
  48099. get namePrefix()
  48100. {
  48101. return this._namePrefix;
  48102. },
  48103.  
  48104. _saveSettings: function()
  48105. {
  48106. var savedSnippets = [];
  48107. for (var id in this._snippets)
  48108. savedSnippets.push(this._snippets[id].serializeToObject());
  48109. this._snippetsSetting.set(savedSnippets);
  48110. },
  48111.  
  48112.  
  48113. snippets: function()
  48114. {
  48115. var result = [];
  48116. for (var id in this._snippets)
  48117. result.push(this._snippets[id]);
  48118. return result;
  48119. },
  48120.  
  48121.  
  48122. snippetForId: function(id)
  48123. {
  48124. return this._snippets[id];
  48125. },
  48126.  
  48127. _loadSettings: function()
  48128. {
  48129. var savedSnippets = this._snippetsSetting.get();
  48130. for (var i = 0; i < savedSnippets.length; ++i)
  48131. this._snippetAdded(WebInspector.Snippet.fromObject(this, savedSnippets[i]));
  48132. },
  48133.  
  48134.  
  48135. deleteSnippet: function(snippet)
  48136. {
  48137. delete this._snippets[snippet.id];
  48138. this._saveSettings();
  48139. },
  48140.  
  48141.  
  48142. createSnippet: function()
  48143. {
  48144. var nextId = this._lastSnippetIdentifierSetting.get() + 1;
  48145. var snippetId = String(nextId);
  48146. this._lastSnippetIdentifierSetting.set(nextId);
  48147. var snippet = new WebInspector.Snippet(this, snippetId);
  48148. this._snippetAdded(snippet);
  48149. this._saveSettings();
  48150. return snippet;
  48151. },
  48152.  
  48153.  
  48154. _snippetAdded: function(snippet)
  48155. {
  48156. this._snippets[snippet.id] = snippet;
  48157. },
  48158.  
  48159. reset: function()
  48160. {
  48161. this._lastSnippetIdentifierSetting.set(0);
  48162. this._snippetsSetting.set([]);
  48163. this._snippets = {};
  48164. },
  48165.  
  48166. __proto__: WebInspector.Object.prototype
  48167. }
  48168.  
  48169.  
  48170. WebInspector.Snippet = function(storage, id, name, content)
  48171. {
  48172. this._storage = storage;
  48173. this._id = id;
  48174. this._name = name || storage.namePrefix + id;
  48175. this._content = content || "";
  48176. }
  48177.  
  48178.  
  48179. WebInspector.Snippet.fromObject = function(storage, serializedSnippet)
  48180. {
  48181. return new WebInspector.Snippet(storage, serializedSnippet.id, serializedSnippet.name, serializedSnippet.content);
  48182. }
  48183.  
  48184. WebInspector.Snippet.prototype = {
  48185.  
  48186. get id()
  48187. {
  48188. return this._id;
  48189. },
  48190.  
  48191.  
  48192. get name()
  48193. {
  48194. return this._name;
  48195. },
  48196.  
  48197. set name(name)
  48198. {
  48199. if (this._name === name)
  48200. return;
  48201.  
  48202. this._name = name;
  48203. this._storage._saveSettings();
  48204. },
  48205.  
  48206.  
  48207. get content()
  48208. {
  48209. return this._content;
  48210. },
  48211.  
  48212. set content(content)
  48213. {
  48214. if (this._content === content)
  48215. return;
  48216.  
  48217. this._content = content;
  48218. this._storage._saveSettings();
  48219. },
  48220.  
  48221.  
  48222. serializeToObject: function()
  48223. {
  48224. var serializedSnippet = {};
  48225. serializedSnippet.id = this.id;
  48226. serializedSnippet.name = this.name;
  48227. serializedSnippet.content = this.content;
  48228. return serializedSnippet;
  48229. },
  48230.  
  48231. __proto__: WebInspector.Object.prototype
  48232. }
  48233.  
  48234.  
  48235.  
  48236.  
  48237.  
  48238.  
  48239. WebInspector.ScriptSnippetModel = function(workspace, networkWorkspaceProvider)
  48240. {
  48241. this._workspace = workspace;
  48242. this._networkWorkspaceProvider = networkWorkspaceProvider;
  48243. this._uiSourceCodeForScriptId = {};
  48244. this._scriptForUISourceCode = new Map();
  48245. this._uiSourceCodeForSnippetId = {};
  48246. this._snippetIdForUISourceCode = new Map();
  48247.  
  48248. this._snippetStorage = new WebInspector.SnippetStorage("script", "Script snippet #");
  48249. this._lastSnippetEvaluationIndexSetting = WebInspector.settings.createSetting("lastSnippetEvaluationIndex", 0);
  48250. this._snippetScriptMapping = new WebInspector.SnippetScriptMapping(this);
  48251. this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._projectWillReset, this);
  48252. this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectDidReset, this._projectDidReset, this);
  48253. this._loadSnippets();
  48254. }
  48255.  
  48256. WebInspector.ScriptSnippetModel.prototype = {
  48257.  
  48258. get scriptMapping()
  48259. {
  48260. return this._snippetScriptMapping;
  48261. },
  48262.  
  48263. _loadSnippets: function()
  48264. {
  48265. var snippets = this._snippetStorage.snippets();
  48266. for (var i = 0; i < snippets.length; ++i)
  48267. this._addScriptSnippet(snippets[i]);
  48268. },
  48269.  
  48270.  
  48271. createScriptSnippet: function()
  48272. {
  48273. var snippet = this._snippetStorage.createSnippet();
  48274. return this._addScriptSnippet(snippet);
  48275. },
  48276.  
  48277.  
  48278. _addScriptSnippet: function(snippet)
  48279. {
  48280. this._networkWorkspaceProvider.addFile(snippet.name, new WebInspector.SnippetContentProvider(snippet), true, false, true);
  48281. var uiSourceCode = this._workspace.uiSourceCodeForURL(snippet.name);
  48282. var scriptFile = new WebInspector.SnippetScriptFile(this, uiSourceCode);
  48283. uiSourceCode.setScriptFile(scriptFile);
  48284. this._snippetIdForUISourceCode.put(uiSourceCode, snippet.id);
  48285. uiSourceCode.setSourceMapping(this._snippetScriptMapping);
  48286. this._uiSourceCodeForSnippetId[snippet.id] = uiSourceCode;
  48287. return uiSourceCode;
  48288. },
  48289.  
  48290.  
  48291. deleteScriptSnippet: function(uiSourceCode)
  48292. {
  48293. var snippetId = this._snippetIdForUISourceCode.get(uiSourceCode);
  48294. var snippet = this._snippetStorage.snippetForId(snippetId);
  48295. this._snippetStorage.deleteSnippet(snippet);
  48296. this._removeBreakpoints(uiSourceCode);
  48297. this._releaseSnippetScript(uiSourceCode);
  48298. delete this._uiSourceCodeForSnippetId[snippet.id];
  48299. this._snippetIdForUISourceCode.remove(uiSourceCode);
  48300. this._networkWorkspaceProvider.removeFile(snippet.name);
  48301. },
  48302.  
  48303.  
  48304. renameScriptSnippet: function(uiSourceCode, newName)
  48305. {
  48306. var breakpointLocations = this._removeBreakpoints(uiSourceCode);
  48307. var snippetId = this._snippetIdForUISourceCode.get(uiSourceCode);
  48308. var snippet = this._snippetStorage.snippetForId(snippetId);
  48309. if (!snippet || !newName || snippet.name === newName)
  48310. return;
  48311. snippet.name = newName;
  48312. this._restoreBreakpoints(uiSourceCode, breakpointLocations);
  48313. uiSourceCode.urlChanged(snippet.name);
  48314. },
  48315.  
  48316.  
  48317. _setScriptSnippetContent: function(uiSourceCode, newContent)
  48318. {
  48319. var snippetId = this._snippetIdForUISourceCode.get(uiSourceCode);
  48320. var snippet = this._snippetStorage.snippetForId(snippetId);
  48321. snippet.content = newContent;
  48322. },
  48323.  
  48324.  
  48325. _scriptSnippetEdited: function(uiSourceCode)
  48326. {
  48327. var script = this._scriptForUISourceCode.get(uiSourceCode);
  48328. if (!script)
  48329. return;
  48330.  
  48331. var breakpointLocations = this._removeBreakpoints(uiSourceCode);
  48332. var createdUISourceCode = this._releaseSnippetScript(uiSourceCode);
  48333. this._restoreBreakpoints(uiSourceCode, breakpointLocations);
  48334. if (createdUISourceCode)
  48335. this._restoreBreakpoints(createdUISourceCode, breakpointLocations);
  48336. },
  48337.  
  48338.  
  48339. _nextEvaluationIndex: function(snippetId)
  48340. {
  48341. var evaluationIndex = this._lastSnippetEvaluationIndexSetting.get() + 1;
  48342. this._lastSnippetEvaluationIndexSetting.set(evaluationIndex);
  48343. return evaluationIndex;
  48344. },
  48345.  
  48346.  
  48347. evaluateScriptSnippet: function(uiSourceCode)
  48348. {
  48349. var breakpointLocations = this._removeBreakpoints(uiSourceCode);
  48350. this._releaseSnippetScript(uiSourceCode);
  48351. this._restoreBreakpoints(uiSourceCode, breakpointLocations);
  48352. var snippetId = this._snippetIdForUISourceCode.get(uiSourceCode);
  48353. var evaluationIndex = this._nextEvaluationIndex(snippetId);
  48354. uiSourceCode._evaluationIndex = evaluationIndex;
  48355. var evaluationUrl = this._evaluationSourceURL(uiSourceCode);
  48356.  
  48357. var expression = uiSourceCode.workingCopy();
  48358.  
  48359.  
  48360.  
  48361.  
  48362.  
  48363. if (WebInspector.debuggerModel.selectedCallFrame() || !Capabilities.separateScriptCompilationAndExecutionEnabled) {
  48364. expression = uiSourceCode.workingCopy() + "\n//@ sourceURL=" + evaluationUrl + "\n";
  48365. WebInspector.evaluateInConsole(expression, true);
  48366. return;
  48367. }
  48368.  
  48369. WebInspector.showConsole();
  48370. DebuggerAgent.compileScript(expression, evaluationUrl, compileCallback.bind(this));
  48371.  
  48372.  
  48373. function compileCallback(error, scriptId, syntaxErrorMessage)
  48374. {
  48375. if (!uiSourceCode || uiSourceCode._evaluationIndex !== evaluationIndex)
  48376. return;
  48377.  
  48378. if (error) {
  48379. console.error(error);
  48380. return;
  48381. }
  48382.  
  48383. if (!scriptId) {
  48384. var consoleMessage = WebInspector.ConsoleMessage.create(
  48385. WebInspector.ConsoleMessage.MessageSource.JS,
  48386. WebInspector.ConsoleMessage.MessageLevel.Error,
  48387. syntaxErrorMessage || "");
  48388. WebInspector.console.addMessage(consoleMessage);
  48389. return;
  48390. }
  48391.  
  48392. var breakpointLocations = this._removeBreakpoints(uiSourceCode);
  48393. this._restoreBreakpoints(uiSourceCode, breakpointLocations);
  48394.  
  48395. this._runScript(scriptId);
  48396. }
  48397. },
  48398.  
  48399.  
  48400. _runScript: function(scriptId)
  48401. {
  48402. var currentExecutionContext = WebInspector.runtimeModel.currentExecutionContext();
  48403. DebuggerAgent.runScript(scriptId, currentExecutionContext ? currentExecutionContext.id : undefined, "console", false, runCallback.bind(this));
  48404.  
  48405.  
  48406. function runCallback(error, result, wasThrown)
  48407. {
  48408. if (error) {
  48409. console.error(error);
  48410. return;
  48411. }
  48412.  
  48413. this._printRunScriptResult(result, wasThrown);
  48414. }
  48415. },
  48416.  
  48417.  
  48418. _printRunScriptResult: function(result, wasThrown)
  48419. {
  48420. var level = (wasThrown ? WebInspector.ConsoleMessage.MessageLevel.Error : WebInspector.ConsoleMessage.MessageLevel.Log);
  48421. var message = WebInspector.ConsoleMessage.create(WebInspector.ConsoleMessage.MessageSource.JS, level, "", undefined, undefined, undefined, undefined, [result]);
  48422. WebInspector.console.addMessage(message)
  48423. },
  48424.  
  48425.  
  48426. _rawLocationToUILocation: function(rawLocation)
  48427. {
  48428. var uiSourceCode = this._uiSourceCodeForScriptId[rawLocation.scriptId];
  48429. return new WebInspector.UILocation(uiSourceCode, rawLocation.lineNumber, rawLocation.columnNumber || 0);
  48430. },
  48431.  
  48432.  
  48433. _uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
  48434. {
  48435. var script = this._scriptForUISourceCode.get(uiSourceCode);
  48436. if (!script)
  48437. return null;
  48438.  
  48439. return WebInspector.debuggerModel.createRawLocation(script, lineNumber, columnNumber);
  48440. },
  48441.  
  48442.  
  48443. _releasedUISourceCodes: function()
  48444. {
  48445. var result = [];
  48446. for (var scriptId in this._uiSourceCodeForScriptId) {
  48447. var uiSourceCode = this._uiSourceCodeForScriptId[scriptId];
  48448. if (uiSourceCode.isTemporary)
  48449. result.push(uiSourceCode);
  48450. }
  48451. return result;
  48452. },
  48453.  
  48454.  
  48455. _addScript: function(script)
  48456. {
  48457. var snippetId = this._snippetIdForSourceURL(script.sourceURL);
  48458. if (!snippetId)
  48459. return;
  48460. var uiSourceCode = this._uiSourceCodeForSnippetId[snippetId];
  48461.  
  48462. if (!uiSourceCode || this._evaluationSourceURL(uiSourceCode) !== script.sourceURL) {
  48463. this._createUISourceCodeForScript(script);
  48464. return;
  48465. }
  48466.  
  48467. console.assert(!this._scriptForUISourceCode.get(uiSourceCode));
  48468. this._uiSourceCodeForScriptId[script.scriptId] = uiSourceCode;
  48469. this._scriptForUISourceCode.put(uiSourceCode, script);
  48470. uiSourceCode.scriptFile().setHasDivergedFromVM(false);
  48471. script.setSourceMapping(this._snippetScriptMapping);
  48472. },
  48473.  
  48474.  
  48475. _createUISourceCodeForScript: function(script)
  48476. {
  48477. var uiSourceCode = this._workspace.addTemporaryUISourceCode(script.sourceURL, script, false, true);
  48478. uiSourceCode.setSourceMapping(this._snippetScriptMapping);
  48479. this._uiSourceCodeForScriptId[script.scriptId] = uiSourceCode;
  48480. this._scriptForUISourceCode.put(uiSourceCode, script);
  48481. script.setSourceMapping(this._snippetScriptMapping);
  48482. return uiSourceCode;
  48483. },
  48484.  
  48485.  
  48486. _removeBreakpoints: function(uiSourceCode)
  48487. {
  48488. var breakpointLocations = WebInspector.breakpointManager.breakpointLocationsForUISourceCode(uiSourceCode);
  48489. for (var i = 0; i < breakpointLocations.length; ++i)
  48490. breakpointLocations[i].breakpoint.remove();
  48491. return breakpointLocations;
  48492. },
  48493.  
  48494.  
  48495. _restoreBreakpoints: function(uiSourceCode, breakpointLocations)
  48496. {
  48497. for (var i = 0; i < breakpointLocations.length; ++i) {
  48498. var uiLocation = breakpointLocations[i].uiLocation;
  48499. var breakpoint = breakpointLocations[i].breakpoint;
  48500. WebInspector.breakpointManager.setBreakpoint(uiSourceCode, uiLocation.lineNumber, breakpoint.condition(), breakpoint.enabled());
  48501. }
  48502. },
  48503.  
  48504.  
  48505. _releaseSnippetScript: function(uiSourceCode)
  48506. {
  48507. var script = this._scriptForUISourceCode.get(uiSourceCode);
  48508. if (!script)
  48509. return null;
  48510.  
  48511. uiSourceCode.scriptFile().setIsDivergingFromVM(true);
  48512. uiSourceCode.scriptFile().setHasDivergedFromVM(true);
  48513. delete this._uiSourceCodeForScriptId[script.scriptId];
  48514. this._scriptForUISourceCode.remove(uiSourceCode);
  48515. delete uiSourceCode._evaluationIndex;
  48516. var createdUISourceCode = this._createUISourceCodeForScript(script);
  48517. uiSourceCode.scriptFile().setIsDivergingFromVM(false);
  48518. return createdUISourceCode;
  48519. },
  48520.  
  48521.  
  48522. _evaluationSourceURL: function(uiSourceCode)
  48523. {
  48524. var evaluationSuffix = "_" + uiSourceCode._evaluationIndex;
  48525. var snippetId = this._snippetIdForUISourceCode.get(uiSourceCode);
  48526. return WebInspector.Script.snippetSourceURLPrefix + snippetId + evaluationSuffix;
  48527. },
  48528.  
  48529.  
  48530. _snippetIdForSourceURL: function(sourceURL)
  48531. {
  48532. var snippetPrefix = WebInspector.Script.snippetSourceURLPrefix;
  48533. if (!sourceURL.startsWith(snippetPrefix))
  48534. return null;
  48535. var splittedURL = sourceURL.substring(snippetPrefix.length).split("_");
  48536. var snippetId = splittedURL[0];
  48537. return snippetId;
  48538. },
  48539.  
  48540. _projectWillReset: function()
  48541. {
  48542. var removedUISourceCodes = this._releasedUISourceCodes();
  48543. this._uiSourceCodeForScriptId = {};
  48544. this._scriptForUISourceCode = new Map();
  48545. this._uiSourceCodeForSnippetId = {};
  48546. this._snippetIdForUISourceCode = new Map();
  48547. },
  48548.  
  48549. _projectDidReset: function()
  48550. {
  48551. this._loadSnippets();
  48552. },
  48553.  
  48554. __proto__: WebInspector.Object.prototype
  48555. }
  48556.  
  48557.  
  48558. WebInspector.SnippetScriptFile = function(scriptSnippetModel, uiSourceCode)
  48559. {
  48560. WebInspector.ScriptFile.call(this);
  48561. this._scriptSnippetModel = scriptSnippetModel;
  48562. this._uiSourceCode = uiSourceCode;
  48563. this._hasDivergedFromVM = true;
  48564. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCommitted, this);
  48565. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChanged, this);
  48566. }
  48567.  
  48568. WebInspector.SnippetScriptFile.prototype = {
  48569.  
  48570. hasDivergedFromVM: function()
  48571. {
  48572. return this._hasDivergedFromVM;
  48573. },
  48574.  
  48575.  
  48576. setHasDivergedFromVM: function(hasDivergedFromVM)
  48577. {
  48578. this._hasDivergedFromVM = hasDivergedFromVM;
  48579. },
  48580.  
  48581.  
  48582. isDivergingFromVM: function()
  48583. {
  48584. return this._isDivergingFromVM;
  48585. },
  48586.  
  48587.  
  48588. setIsDivergingFromVM: function(isDivergingFromVM)
  48589. {
  48590. this._isDivergingFromVM = isDivergingFromVM;
  48591. },
  48592.  
  48593. _workingCopyCommitted: function()
  48594. {
  48595. this._scriptSnippetModel._setScriptSnippetContent(this._uiSourceCode, this._uiSourceCode.workingCopy());
  48596. },
  48597.  
  48598. _workingCopyChanged: function()
  48599. {
  48600. this._scriptSnippetModel._scriptSnippetEdited(this._uiSourceCode);
  48601. },
  48602.  
  48603. __proto__: WebInspector.Object.prototype
  48604. }
  48605.  
  48606.  
  48607. WebInspector.SnippetScriptMapping = function(scriptSnippetModel)
  48608. {
  48609. this._scriptSnippetModel = scriptSnippetModel;
  48610. }
  48611.  
  48612. WebInspector.SnippetScriptMapping.prototype = {
  48613.  
  48614. rawLocationToUILocation: function(rawLocation)
  48615. {
  48616. var debuggerModelLocation =   rawLocation;
  48617. return this._scriptSnippetModel._rawLocationToUILocation(debuggerModelLocation);
  48618. },
  48619.  
  48620.  
  48621. uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
  48622. {
  48623. return this._scriptSnippetModel._uiLocationToRawLocation(uiSourceCode, lineNumber, columnNumber);
  48624. },
  48625.  
  48626.  
  48627. snippetIdForSourceURL: function(sourceURL)
  48628. {
  48629. return this._scriptSnippetModel._snippetIdForSourceURL(sourceURL);
  48630. },
  48631.  
  48632.  
  48633. addScript: function(script)
  48634. {
  48635. this._scriptSnippetModel._addScript(script);
  48636. }
  48637. }
  48638.  
  48639.  
  48640. WebInspector.SnippetContentProvider = function(snippet)
  48641. {
  48642. WebInspector.StaticContentProvider.call(this, WebInspector.resourceTypes.Script, snippet.content);
  48643. }
  48644.  
  48645. WebInspector.SnippetContentProvider.prototype = {
  48646. __proto__: WebInspector.StaticContentProvider.prototype
  48647. }
  48648.  
  48649.  
  48650. WebInspector.scriptSnippetModel = null;
  48651.  
  48652.  
  48653.  
  48654.  
  48655.  
  48656.  
  48657. WebInspector.Progress = function()
  48658. {
  48659. }
  48660.  
  48661. WebInspector.Progress.prototype = {
  48662.  
  48663. setTotalWork: function(totalWork) { },
  48664.  
  48665.  
  48666. setTitle: function(title) { },
  48667.  
  48668.  
  48669. setWorked: function(worked, title) { },
  48670.  
  48671.  
  48672. worked: function(worked) { },
  48673.  
  48674. done: function() { },
  48675.  
  48676.  
  48677. isCanceled: function() { return false; }
  48678. }
  48679.  
  48680.  
  48681. WebInspector.CompositeProgress = function(parent)
  48682. {
  48683. this._parent = parent;
  48684. this._children = [];
  48685. this._childrenDone = 0;
  48686. this._parent.setTotalWork(1);
  48687. this._parent.setWorked(0);
  48688. }
  48689.  
  48690. WebInspector.CompositeProgress.prototype = {
  48691. _childDone: function()
  48692. {
  48693. if (++this._childrenDone === this._children.length)
  48694. this._parent.done();
  48695. },
  48696.  
  48697.  
  48698. createSubProgress: function(weight)
  48699. {
  48700. var child = new WebInspector.SubProgress(this, weight);
  48701. this._children.push(child);
  48702. return child;
  48703. },
  48704.  
  48705. _update: function()
  48706. {
  48707. var totalWeights = 0;
  48708. var done = 0;
  48709.  
  48710. for (var i = 0; i < this._children.length; ++i) {
  48711. var child = this._children[i];
  48712. if (child._totalWork)
  48713. done += child._weight * child._worked / child._totalWork;
  48714. totalWeights += child._weight;
  48715. }
  48716. this._parent.setWorked(done / totalWeights);
  48717. }
  48718. }
  48719.  
  48720.  
  48721. WebInspector.SubProgress = function(composite, weight)
  48722. {
  48723. this._composite = composite;
  48724. this._weight = weight || 1;
  48725. this._worked = 0;
  48726. }
  48727.  
  48728. WebInspector.SubProgress.prototype = {
  48729.  
  48730. isCanceled: function()
  48731. {
  48732. return this._composite._parent.isCanceled();
  48733. },
  48734.  
  48735.  
  48736. setTitle: function(title)
  48737. {
  48738. this._composite._parent.setTitle(title);
  48739. },
  48740.  
  48741. done: function()
  48742. {
  48743. this.setWorked(this._totalWork);
  48744. this._composite._childDone();
  48745. },
  48746.  
  48747.  
  48748. setTotalWork: function(totalWork)
  48749. {
  48750. this._totalWork = totalWork;
  48751. this._composite._update();
  48752. },
  48753.  
  48754.  
  48755. setWorked: function(worked, title)
  48756. {
  48757. this._worked = worked;
  48758. if (typeof title !== "undefined")
  48759. this.setTitle(title);
  48760. this._composite._update();
  48761. },
  48762.  
  48763.  
  48764. worked: function(worked)
  48765. {
  48766. this.setWorked(this._worked + (worked || 1));
  48767. }
  48768. }
  48769.  
  48770.  
  48771.  
  48772.  
  48773.  
  48774.  
  48775. WebInspector.ProgressIndicator = function()
  48776. {
  48777. this.element = document.createElement("div");
  48778. this.element.className = "progress-bar-container";
  48779. this._labelElement = this.element.createChild("span");
  48780. this._progressElement = this.element.createChild("progress");
  48781. this._stopButton = new WebInspector.StatusBarButton(WebInspector.UIString("Cancel"), "progress-bar-stop-button");
  48782. this._stopButton.addEventListener("click", this.cancel, this);
  48783. this.element.appendChild(this._stopButton.element);
  48784. this._isCanceled = false;
  48785. this._worked = 0;
  48786. }
  48787.  
  48788. WebInspector.ProgressIndicator.Events = {
  48789. Done: "Done"
  48790. }
  48791.  
  48792. WebInspector.ProgressIndicator.prototype = {
  48793.  
  48794. show: function(parent)
  48795. {
  48796. parent.appendChild(this.element);
  48797. },
  48798.  
  48799. hide: function()
  48800. {
  48801. var parent = this.element.parentElement;
  48802. if (parent)
  48803. parent.removeChild(this.element);
  48804. },
  48805.  
  48806. done: function()
  48807. {
  48808. if (this._isDone)
  48809. return;
  48810. this._isDone = true;
  48811. this.hide();
  48812. this.dispatchEventToListeners(WebInspector.ProgressIndicator.Events.Done);
  48813. },
  48814.  
  48815. cancel: function()
  48816. {
  48817. this._isCanceled = true;
  48818. },
  48819.  
  48820. isCanceled: function()
  48821. {
  48822. return this._isCanceled;
  48823. },
  48824.  
  48825.  
  48826. setTitle: function(title)
  48827. {
  48828. this._labelElement.textContent = title;
  48829. },
  48830.  
  48831.  
  48832. setTotalWork: function(totalWork)
  48833. {
  48834. this._progressElement.max = totalWork;
  48835. },
  48836.  
  48837.  
  48838. setWorked: function(worked, title)
  48839. {
  48840. this._worked = worked;
  48841. this._progressElement.value = worked;
  48842. if (title)
  48843. this.setTitle(title);
  48844. },
  48845.  
  48846.  
  48847. worked: function(worked)
  48848. {
  48849. this.setWorked(this._worked + (worked || 1));
  48850. },
  48851.  
  48852. __proto__: WebInspector.Object.prototype
  48853. }
  48854.  
  48855.  
  48856.  
  48857.  
  48858.  
  48859.  
  48860. WebInspector.StylesSourceMapping = function(workspace)
  48861. {
  48862. this._workspace = workspace;
  48863. this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._reset, this);
  48864. this._workspace.addEventListener(WebInspector.UISourceCodeProvider.Events.UISourceCodeAdded, this._uiSourceCodeAddedToWorkspace, this);
  48865.  
  48866. this._uiSourceCodeForURL = {};
  48867. }
  48868.  
  48869. WebInspector.StylesSourceMapping.prototype = {
  48870.  
  48871. rawLocationToUILocation: function(rawLocation)
  48872. {
  48873. var location =   (rawLocation);
  48874. var uiSourceCode = this._uiSourceCodeForURL[location.url];
  48875. return new WebInspector.UILocation(uiSourceCode, location.lineNumber, 0);
  48876. },
  48877.  
  48878.  
  48879. uiLocationToRawLocation: function(uiSourceCode, lineNumber, columnNumber)
  48880. {
  48881. return new WebInspector.CSSLocation(uiSourceCode.contentURL() || "", lineNumber);
  48882. },
  48883.  
  48884. _uiSourceCodeAddedToWorkspace: function(event)
  48885. {
  48886. var uiSourceCode =   (event.data);
  48887. if (!uiSourceCode.url || this._uiSourceCodeForURL[uiSourceCode.url])
  48888. return;
  48889. if (uiSourceCode.contentType() !== WebInspector.resourceTypes.Stylesheet)
  48890. return;
  48891. if (!WebInspector.resourceForURL(uiSourceCode.url))
  48892. return;
  48893.  
  48894. this._addUISourceCode(uiSourceCode);
  48895. },
  48896.  
  48897.  
  48898. _addUISourceCode: function(uiSourceCode)
  48899. {
  48900. this._uiSourceCodeForURL[uiSourceCode.url] = uiSourceCode;
  48901. uiSourceCode.setSourceMapping(this);
  48902. var styleFile = new WebInspector.StyleFile(uiSourceCode);
  48903. uiSourceCode.setStyleFile(styleFile);
  48904. WebInspector.cssModel.setSourceMapping(uiSourceCode.url, this);
  48905. },
  48906.  
  48907. _reset: function()
  48908. {
  48909. this._uiSourceCodeForURL = {};
  48910. WebInspector.cssModel.resetSourceMappings();
  48911. }
  48912. }
  48913.  
  48914.  
  48915. WebInspector.StyleFile = function(uiSourceCode)
  48916. {
  48917. this._uiSourceCode = uiSourceCode;
  48918. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyChanged, this._workingCopyChanged, this);
  48919. this._uiSourceCode.addEventListener(WebInspector.UISourceCode.Events.WorkingCopyCommitted, this._workingCopyCommitted, this);
  48920. }
  48921.  
  48922. WebInspector.StyleFile.updateTimeout = 200;
  48923.  
  48924. WebInspector.StyleFile.prototype = {
  48925. _workingCopyCommitted: function(event)
  48926. {
  48927. if (this._isAddingRevision)
  48928. return;
  48929.  
  48930. this._commitIncrementalEdit(true);
  48931. },
  48932.  
  48933. _workingCopyChanged: function(event)
  48934. {
  48935. if (this._isAddingRevision)
  48936. return;
  48937.  
  48938.  
  48939. if (WebInspector.StyleFile.updateTimeout >= 0) {
  48940. this._incrementalUpdateTimer = setTimeout(this._commitIncrementalEdit.bind(this, false), WebInspector.StyleFile.updateTimeout)
  48941. } else
  48942. this._commitIncrementalEdit(false);
  48943. },
  48944.  
  48945.  
  48946. _commitIncrementalEdit: function(majorChange)
  48947. {
  48948. this._clearIncrementalUpdateTimer();
  48949. WebInspector.styleContentBinding.setStyleContent(this._uiSourceCode, this._uiSourceCode.workingCopy(), majorChange, this._styleContentSet.bind(this));
  48950. },
  48951.  
  48952.  
  48953. _styleContentSet: function(error)
  48954. {
  48955. if (error)
  48956. WebInspector.showErrorMessage(error);
  48957. },
  48958.  
  48959. _clearIncrementalUpdateTimer: function()
  48960. {
  48961. if (!this._incrementalUpdateTimer)
  48962. return;
  48963. clearTimeout(this._incrementalUpdateTimer);
  48964. delete this._incrementalUpdateTimer;
  48965. },
  48966.  
  48967.  
  48968. addRevision: function(content)
  48969. {
  48970. this._isAddingRevision = true;
  48971. this._uiSourceCode.addRevision(content);
  48972. delete this._isAddingRevision;
  48973. },
  48974. }
  48975.  
  48976.  
  48977.  
  48978. WebInspector.StyleContentBinding = function(cssModel)
  48979. {
  48980. this._cssModel = cssModel;
  48981. this._cssModel.addEventListener(WebInspector.CSSStyleModel.Events.StyleSheetChanged, this._styleSheetChanged, this);
  48982. }
  48983.  
  48984. WebInspector.StyleContentBinding.prototype = {
  48985.  
  48986. setStyleContent: function(uiSourceCode, content, majorChange, userCallback)
  48987. {
  48988. var resource = WebInspector.resourceForURL(uiSourceCode.url);
  48989. if (!resource) {
  48990. userCallback("No resource found: " + uiSourceCode.url);
  48991. return;
  48992. }
  48993.  
  48994. this._cssModel.resourceBinding().requestStyleSheetIdForResource(resource, callback.bind(this));
  48995.  
  48996.  
  48997. function callback(styleSheetId)
  48998. {
  48999. if (!styleSheetId) {
  49000. userCallback("No stylesheet found: " + resource.frameId + ":" + resource.url);
  49001. return;
  49002. }
  49003.  
  49004. this._innerSetContent(styleSheetId, content, majorChange, userCallback, null);
  49005. }
  49006. },
  49007.  
  49008.  
  49009. _innerSetContent: function(styleSheetId, content, majorChange, userCallback)
  49010. {
  49011. this._isSettingContent = true;
  49012. function callback(error)
  49013. {
  49014. userCallback(error);
  49015. delete this._isSettingContent;
  49016. }
  49017. this._cssModel.setStyleSheetText(styleSheetId, content, majorChange, callback.bind(this));
  49018. },
  49019.  
  49020.  
  49021. _styleSheetChanged: function(event)
  49022. {
  49023. if (this._isSettingContent)
  49024. return;
  49025.  
  49026. if (!event.data.majorChange)
  49027. return;
  49028.  
  49029.  
  49030. function callback(error, content)
  49031. {
  49032. if (!error)
  49033. this._innerStyleSheetChanged(event.data.styleSheetId, content);
  49034. }
  49035. CSSAgent.getStyleSheetText(event.data.styleSheetId, callback.bind(this));
  49036. },
  49037.  
  49038.  
  49039. _innerStyleSheetChanged: function(styleSheetId, content)
  49040. {
  49041.  
  49042. function callback(styleSheetURL)
  49043. {
  49044. if (typeof styleSheetURL !== "string")
  49045. return;
  49046.  
  49047. var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(styleSheetURL);
  49048. if (!uiSourceCode)
  49049. return;
  49050.  
  49051. if (uiSourceCode.styleFile())
  49052. uiSourceCode.styleFile().addRevision(content);
  49053. }
  49054.  
  49055. this._cssModel.resourceBinding().requestResourceURLForStyleSheetId(styleSheetId, callback.bind(this));
  49056. },
  49057. }
  49058.  
  49059.  
  49060. WebInspector.styleContentBinding = null;
  49061.  
  49062.  
  49063.  
  49064.  
  49065.  
  49066.  
  49067. WebInspector.NetworkUISourceCodeProvider = function(workspace, networkWorkspaceProvider)
  49068. {
  49069. this._workspace = workspace;
  49070. this._networkWorkspaceProvider = networkWorkspaceProvider;
  49071. WebInspector.resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.ResourceAdded, this._resourceAdded, this);
  49072. this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectWillReset, this._projectWillReset, this);
  49073. this._workspace.addEventListener(WebInspector.Workspace.Events.ProjectDidReset, this._projectDidReset, this);
  49074. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.ParsedScriptSource, this._parsedScriptSource, this);
  49075.  
  49076. this._processedURLs = {};
  49077. this._lastDynamicAnonymousScriptIndexForURL = {};
  49078. }
  49079.  
  49080. WebInspector.NetworkUISourceCodeProvider.prototype = {
  49081. _populate: function()
  49082. {
  49083. function populateFrame(frame)
  49084. {
  49085. for (var i = 0; i < frame.childFrames.length; ++i)
  49086. populateFrame.call(this, frame.childFrames[i]);
  49087.  
  49088. var resources = frame.resources();
  49089. for (var i = 0; i < resources.length; ++i)
  49090. this._resourceAdded({data:resources[i]});
  49091. }
  49092.  
  49093. populateFrame.call(this, WebInspector.resourceTreeModel.mainFrame);
  49094. },
  49095.  
  49096.  
  49097. _parsedScriptSource: function(event)
  49098. {
  49099. var script =   (event.data);
  49100. if (!script.sourceURL || script.isInlineScript())
  49101. return;
  49102. if (WebInspector.experimentsSettings.snippetsSupport.isEnabled() && script.isSnippet())
  49103. return;
  49104. var isDynamicAnonymousScript;
  49105.  
  49106.  
  49107.  
  49108.  
  49109. if (!script.hasSourceURL && !script.isContentScript) {
  49110. var requestURL = script.sourceURL.replace(/#.*/, "");
  49111. if (WebInspector.resourceForURL(requestURL) || WebInspector.networkLog.requestForURL(requestURL))
  49112. return;
  49113. }
  49114.  
  49115. if (script.isContentScript && !script.hasSourceURL) {
  49116. var parsedURL = new WebInspector.ParsedURL(script.sourceURL);
  49117. if (!parsedURL.host)
  49118. return;
  49119. }
  49120. this._addFile(script.sourceURL, script, script.isContentScript);
  49121. },
  49122.  
  49123.  
  49124. _resourceAdded: function(event)
  49125. {
  49126. var resource =   (event.data);
  49127. this._addFile(resource.url, resource);
  49128. },
  49129.  
  49130.  
  49131. _addFile: function(url, contentProvider, isContentScript)
  49132. {
  49133. var type = contentProvider.contentType();
  49134. if (type !== WebInspector.resourceTypes.Stylesheet && type !== WebInspector.resourceTypes.Document && type !== WebInspector.resourceTypes.Script)
  49135. return;
  49136. if (this._processedURLs[url])
  49137. return;
  49138. this._processedURLs[url] = true;
  49139. var isEditable = type !== WebInspector.resourceTypes.Document;
  49140. this._networkWorkspaceProvider.addFile(url, contentProvider, isEditable, isContentScript);
  49141. },
  49142.  
  49143. _projectWillReset: function()
  49144. {
  49145. this._processedURLs = {};
  49146. this._lastDynamicAnonymousScriptIndexForURL = {};
  49147. },
  49148.  
  49149. _projectDidReset: function()
  49150. {
  49151. this._populate();
  49152. }
  49153. }
  49154.  
  49155.  
  49156.  
  49157.  
  49158.  
  49159.  
  49160. WebInspector.ElementsPanelDescriptor = function()
  49161. {
  49162. WebInspector.PanelDescriptor.call(this, "elements", WebInspector.UIString("Elements"), "ElementsPanel", "ElementsPanel.js");
  49163. WebInspector.ContextMenu.registerProvider(this);
  49164. }
  49165.  
  49166. WebInspector.ElementsPanelDescriptor.prototype = {
  49167.  
  49168. appendApplicableItems: function(event, contextMenu, target)
  49169. {
  49170. if (!(target instanceof WebInspector.RemoteObject))
  49171. return;
  49172. var remoteObject =   (target);
  49173. if (remoteObject.subtype !== "node")
  49174. return;
  49175. this.panel().appendApplicableItems(event, contextMenu, target);
  49176. },
  49177.  
  49178. registerShortcuts: function()
  49179. {
  49180. var elementsSection = WebInspector.shortcutsScreen.section(WebInspector.UIString("Elements Panel"));
  49181.  
  49182. var navigate = WebInspector.ElementsPanelDescriptor.ShortcutKeys.NavigateUp.concat(WebInspector.ElementsPanelDescriptor.ShortcutKeys.NavigateDown);
  49183. elementsSection.addRelatedKeys(navigate, WebInspector.UIString("Navigate elements"));
  49184.  
  49185. var expandCollapse = WebInspector.ElementsPanelDescriptor.ShortcutKeys.Expand.concat(WebInspector.ElementsPanelDescriptor.ShortcutKeys.Collapse);
  49186. elementsSection.addRelatedKeys(expandCollapse, WebInspector.UIString("Expand/collapse"));
  49187.  
  49188. elementsSection.addAlternateKeys(WebInspector.ElementsPanelDescriptor.ShortcutKeys.EditAttribute, WebInspector.UIString("Edit attribute"));
  49189. elementsSection.addAlternateKeys(WebInspector.ElementsPanelDescriptor.ShortcutKeys.HideElement, WebInspector.UIString("Hide element"));
  49190. elementsSection.addAlternateKeys(WebInspector.ElementsPanelDescriptor.ShortcutKeys.ToggleEditAsHTML, WebInspector.UIString("Toggle edit as HTML"));
  49191.  
  49192. var stylesPaneSection = WebInspector.shortcutsScreen.section(WebInspector.UIString("Styles Pane"));
  49193.  
  49194. var nextPreviousProperty = WebInspector.ElementsPanelDescriptor.ShortcutKeys.NextProperty.concat(WebInspector.ElementsPanelDescriptor.ShortcutKeys.PreviousProperty);
  49195. stylesPaneSection.addRelatedKeys(nextPreviousProperty, WebInspector.UIString("Next/previous property"));
  49196.  
  49197. stylesPaneSection.addRelatedKeys(WebInspector.ElementsPanelDescriptor.ShortcutKeys.IncrementValue, WebInspector.UIString("Increment value"));
  49198. stylesPaneSection.addRelatedKeys(WebInspector.ElementsPanelDescriptor.ShortcutKeys.DecrementValue, WebInspector.UIString("Decrement value"));
  49199.  
  49200. stylesPaneSection.addAlternateKeys(WebInspector.ElementsPanelDescriptor.ShortcutKeys.IncrementBy10, WebInspector.UIString("Increment by %f", 10));
  49201. stylesPaneSection.addAlternateKeys(WebInspector.ElementsPanelDescriptor.ShortcutKeys.DecrementBy10, WebInspector.UIString("Decrement by %f", 10));
  49202.  
  49203. stylesPaneSection.addAlternateKeys(WebInspector.ElementsPanelDescriptor.ShortcutKeys.IncrementBy100, WebInspector.UIString("Increment by %f", 100));
  49204. stylesPaneSection.addAlternateKeys(WebInspector.ElementsPanelDescriptor.ShortcutKeys.DecrementBy100, WebInspector.UIString("Decrement by %f", 100));
  49205.  
  49206. stylesPaneSection.addAlternateKeys(WebInspector.ElementsPanelDescriptor.ShortcutKeys.IncrementBy01, WebInspector.UIString("Increment by %f", 0.1));
  49207. stylesPaneSection.addAlternateKeys(WebInspector.ElementsPanelDescriptor.ShortcutKeys.DecrementBy01, WebInspector.UIString("Decrement by %f", 0.1));
  49208. },
  49209.  
  49210. __proto__: WebInspector.PanelDescriptor.prototype
  49211. }
  49212.  
  49213. WebInspector.ElementsPanelDescriptor.ShortcutKeys = {
  49214. NavigateUp: [
  49215. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Up)
  49216. ],
  49217.  
  49218. NavigateDown: [
  49219. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Down)
  49220. ],
  49221.  
  49222. Expand: [
  49223. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Right)
  49224. ],
  49225.  
  49226. Collapse: [
  49227. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Left)
  49228. ],
  49229.  
  49230. EditAttribute: [
  49231. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Enter)
  49232. ],
  49233.  
  49234. HideElement: [
  49235. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.H)
  49236. ],
  49237.  
  49238. ToggleEditAsHTML: [
  49239. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.F2)
  49240. ],
  49241.  
  49242. NextProperty: [
  49243. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Tab)
  49244. ],
  49245.  
  49246. PreviousProperty: [
  49247. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Tab, WebInspector.KeyboardShortcut.Modifiers.Shift)
  49248. ],
  49249.  
  49250. IncrementValue: [
  49251. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Up)
  49252. ],
  49253.  
  49254. DecrementValue: [
  49255. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Down)
  49256. ],
  49257.  
  49258. IncrementBy10: [
  49259. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.PageUp),
  49260. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Up, WebInspector.KeyboardShortcut.Modifiers.Shift)
  49261. ],
  49262.  
  49263. DecrementBy10: [
  49264. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.PageDown),
  49265. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Down, WebInspector.KeyboardShortcut.Modifiers.Shift)
  49266. ],
  49267.  
  49268. IncrementBy100: [
  49269. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.PageUp, WebInspector.KeyboardShortcut.Modifiers.Shift)
  49270. ],
  49271.  
  49272. DecrementBy100: [
  49273. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.PageDown, WebInspector.KeyboardShortcut.Modifiers.Shift)
  49274. ],
  49275.  
  49276. IncrementBy01: [
  49277. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.PageUp, WebInspector.KeyboardShortcut.Modifiers.Alt)
  49278. ],
  49279.  
  49280. DecrementBy01: [
  49281. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.PageDown, WebInspector.KeyboardShortcut.Modifiers.Alt)
  49282. ]
  49283. };
  49284.  
  49285.  
  49286.  
  49287.  
  49288.  
  49289.  
  49290.  
  49291. WebInspector.NetworkPanelDescriptor = function()
  49292. {
  49293. WebInspector.PanelDescriptor.call(this, "network", WebInspector.UIString("Network"), "NetworkPanel", "NetworkPanel.js");
  49294. WebInspector.ContextMenu.registerProvider(this);
  49295. }
  49296.  
  49297. WebInspector.NetworkPanelDescriptor.prototype = {
  49298.  
  49299. appendApplicableItems: function(event, contextMenu, target)
  49300. {
  49301. if (!(target instanceof WebInspector.NetworkRequest))
  49302. return;
  49303. this.panel().appendApplicableItems(event, contextMenu, target);
  49304. },
  49305.  
  49306. __proto__: WebInspector.PanelDescriptor.prototype
  49307. }
  49308.  
  49309.  
  49310.  
  49311.  
  49312.  
  49313.  
  49314. WebInspector.ScriptsPanelDescriptor = function()
  49315. {
  49316. WebInspector.PanelDescriptor.call(this, "scripts", WebInspector.UIString("Sources"), "ScriptsPanel", "ScriptsPanel.js");
  49317. WebInspector.ContextMenu.registerProvider(this);
  49318. }
  49319.  
  49320. WebInspector.ScriptsPanelDescriptor.prototype = {
  49321.  
  49322. appendApplicableItems: function(event, contextMenu, target)
  49323. {
  49324. var hasApplicableItems = target instanceof WebInspector.UISourceCode;
  49325.  
  49326. if (!hasApplicableItems && target instanceof WebInspector.RemoteObject) {
  49327. var remoteObject =   (target);
  49328. if (remoteObject.type !== "function")
  49329. return;
  49330. }
  49331.  
  49332. this.panel().appendApplicableItems(event, contextMenu, target);
  49333. },
  49334.  
  49335. registerShortcuts: function()
  49336. {
  49337. var section = WebInspector.shortcutsScreen.section(WebInspector.UIString("Sources Panel"));
  49338.  
  49339. section.addAlternateKeys(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.PauseContinue, WebInspector.UIString("Pause/Continue"));
  49340. section.addAlternateKeys(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.StepOver, WebInspector.UIString("Step over"));
  49341. section.addAlternateKeys(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.StepInto, WebInspector.UIString("Step into"));
  49342. section.addAlternateKeys(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.StepOut, WebInspector.UIString("Step out"));
  49343.  
  49344. var nextAndPrevFrameKeys = WebInspector.ScriptsPanelDescriptor.ShortcutKeys.NextCallFrame.concat(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.PrevCallFrame);
  49345. section.addRelatedKeys(nextAndPrevFrameKeys, WebInspector.UIString("Next/previous call frame"));
  49346.  
  49347. section.addAlternateKeys(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.EvaluateSelectionInConsole, WebInspector.UIString("Evaluate selection in console"));
  49348. section.addAlternateKeys(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.GoToMember, WebInspector.UIString("Go to member"));
  49349. section.addAlternateKeys(WebInspector.ScriptsPanelDescriptor.ShortcutKeys.ToggleBreakpoint, WebInspector.UIString("Toggle breakpoint"));
  49350. },
  49351.  
  49352. __proto__: WebInspector.PanelDescriptor.prototype
  49353. }
  49354.  
  49355. WebInspector.ScriptsPanelDescriptor.ShortcutKeys = {
  49356. PauseContinue: [
  49357. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.F8),
  49358. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Slash, WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)
  49359. ],
  49360.  
  49361. StepOver: [
  49362. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.F10),
  49363. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.SingleQuote, WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)
  49364. ],
  49365.  
  49366. StepInto: [
  49367. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.F11),
  49368. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Semicolon, WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)
  49369. ],
  49370.  
  49371. StepOut: [
  49372. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.F11, WebInspector.KeyboardShortcut.Modifiers.Shift),
  49373. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Semicolon, WebInspector.KeyboardShortcut.Modifiers.Shift | WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)
  49374. ],
  49375.  
  49376. EvaluateSelectionInConsole: [
  49377. WebInspector.KeyboardShortcut.makeDescriptor("e", WebInspector.KeyboardShortcut.Modifiers.Shift | WebInspector.KeyboardShortcut.Modifiers.Ctrl)
  49378. ],
  49379.  
  49380. GoToMember: [
  49381. WebInspector.KeyboardShortcut.makeDescriptor("o", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta | WebInspector.KeyboardShortcut.Modifiers.Shift)
  49382. ],
  49383.  
  49384. ToggleBreakpoint: [
  49385. WebInspector.KeyboardShortcut.makeDescriptor("b", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)
  49386. ],
  49387.  
  49388. NextCallFrame: [
  49389. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Period, WebInspector.KeyboardShortcut.Modifiers.Ctrl)
  49390. ],
  49391.  
  49392. PrevCallFrame: [
  49393. WebInspector.KeyboardShortcut.makeDescriptor(WebInspector.KeyboardShortcut.Keys.Comma, WebInspector.KeyboardShortcut.Modifiers.Ctrl)
  49394. ]
  49395. };
  49396.  
  49397.  
  49398.  
  49399.  
  49400.  
  49401.  
  49402. WebInspector.TimelinePanelDescriptor = function()
  49403. {
  49404. WebInspector.PanelDescriptor.call(this, "timeline", WebInspector.UIString("Timeline"), "TimelinePanel", "TimelinePanel.js");
  49405. }
  49406.  
  49407. WebInspector.TimelinePanelDescriptor.prototype = {
  49408. registerShortcuts: function()
  49409. {
  49410. var section = WebInspector.shortcutsScreen.section(WebInspector.UIString("Timeline Panel"));
  49411. section.addAlternateKeys(WebInspector.TimelinePanelDescriptor.ShortcutKeys.StartStopRecording, WebInspector.UIString("Start/stop recording"));
  49412. if (InspectorFrontendHost.canSave())
  49413. section.addAlternateKeys(WebInspector.TimelinePanelDescriptor.ShortcutKeys.SaveToFile, WebInspector.UIString("Save timeline data"));
  49414. section.addAlternateKeys(WebInspector.TimelinePanelDescriptor.ShortcutKeys.LoadFromFile, WebInspector.UIString("Load timeline data"));
  49415. },
  49416.  
  49417. __proto__: WebInspector.PanelDescriptor.prototype
  49418. }
  49419.  
  49420. WebInspector.TimelinePanelDescriptor.ShortcutKeys = {
  49421. StartStopRecording: [
  49422. WebInspector.KeyboardShortcut.makeDescriptor("e", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)
  49423. ],
  49424.  
  49425. SaveToFile: [
  49426. WebInspector.KeyboardShortcut.makeDescriptor("s", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)
  49427. ],
  49428.  
  49429. LoadFromFile: [
  49430. WebInspector.KeyboardShortcut.makeDescriptor("o", WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta)
  49431. ]
  49432. }
  49433.  
  49434.  
  49435.  
  49436.  
  49437.  
  49438.  
  49439. WebInspector.DockController = function()
  49440. {
  49441. this._dockToggleButton = new WebInspector.StatusBarButton("", "dock-status-bar-item", 3);
  49442. this._dockToggleButtonOption = new WebInspector.StatusBarButton("", "dock-status-bar-item", 3);
  49443. this._dockToggleButton.addEventListener("click", this._toggleDockState, this);
  49444. this._dockToggleButtonOption.addEventListener("click", this._toggleDockState, this);
  49445. if (Preferences.showDockToRight)
  49446. this._dockToggleButton.makeLongClickEnabled(this._createDockOptions.bind(this));
  49447.  
  49448. this.setDockSide(WebInspector.queryParamsObject["dockSide"] || "bottom");
  49449. WebInspector.settings.showToolbarIcons.addChangeListener(this._updateUI.bind(this));
  49450. }
  49451.  
  49452. WebInspector.DockController.State = {
  49453. DockedToBottom: "bottom",
  49454. DockedToRight: "right",
  49455. Undocked: "undocked"
  49456. }
  49457.  
  49458. WebInspector.DockController.prototype = {
  49459.  
  49460. get element()
  49461. {
  49462. return this._dockToggleButton.element;
  49463. },
  49464.  
  49465.  
  49466. setDockSide: function(dockSide)
  49467. {
  49468. if (this._dockSide === dockSide)
  49469. return;
  49470.  
  49471. if (this._dockSide)
  49472. WebInspector.settings.lastDockState.set(this._dockSide);
  49473.  
  49474. this._dockSide = dockSide;
  49475. if (dockSide === WebInspector.DockController.State.Undocked) 
  49476. WebInspector.userMetrics.WindowDocked.record();
  49477. else
  49478. WebInspector.userMetrics.WindowUndocked.record();
  49479. this._updateUI();
  49480. },
  49481.  
  49482.  
  49483. setDockingUnavailable: function(unavailable)
  49484. {
  49485. this._isDockingUnavailable = unavailable;
  49486. this._updateUI();
  49487. },
  49488.  
  49489. _updateUI: function()
  49490. {
  49491. var body = document.body;
  49492. switch (this._dockSide) {
  49493. case WebInspector.DockController.State.DockedToBottom:
  49494. body.removeStyleClass("undocked");
  49495. body.removeStyleClass("dock-to-right");
  49496. body.addStyleClass("dock-to-bottom");
  49497. break;
  49498. case WebInspector.DockController.State.DockedToRight: 
  49499. body.removeStyleClass("undocked");
  49500. body.addStyleClass("dock-to-right");
  49501. body.removeStyleClass("dock-to-bottom");
  49502. break;
  49503. case WebInspector.DockController.State.Undocked: 
  49504. body.addStyleClass("undocked");
  49505. body.removeStyleClass("dock-to-right");
  49506. body.removeStyleClass("dock-to-bottom");
  49507. break;
  49508. }
  49509.  
  49510. if (WebInspector.toolbar)
  49511. WebInspector.toolbar.setDockedToBottom(this._dockSide === WebInspector.DockController.State.DockedToBottom);
  49512. if (WebInspector.settings.showToolbarIcons.get())
  49513. document.body.addStyleClass("show-toolbar-icons");
  49514. else
  49515. document.body.removeStyleClass("show-toolbar-icons");
  49516.  
  49517. if (this._isDockingUnavailable) {
  49518. this._dockToggleButton.state = "undock";
  49519. this._dockToggleButton.setEnabled(false);
  49520. return;
  49521. }
  49522.  
  49523. this._dockToggleButton.setEnabled(true);
  49524.  
  49525.  
  49526. var sides = [WebInspector.DockController.State.DockedToBottom, WebInspector.DockController.State.Undocked, WebInspector.DockController.State.DockedToRight];
  49527. sides.remove(this._dockSide);
  49528. var lastState = WebInspector.settings.lastDockState.get();
  49529.  
  49530. sides.remove(lastState);
  49531. if (sides.length === 2) { 
  49532. lastState = sides[0];
  49533. sides.remove(lastState);
  49534. }
  49535. this._decorateButtonForTargetState(this._dockToggleButton, lastState);
  49536. this._decorateButtonForTargetState(this._dockToggleButtonOption, sides[0]);
  49537. },
  49538.  
  49539.  
  49540. _decorateButtonForTargetState: function(button, state)
  49541. {
  49542. switch (state) {
  49543. case WebInspector.DockController.State.DockedToBottom:
  49544. button.title = WebInspector.UIString("Dock to main window.");
  49545. button.state = "bottom";
  49546. break;
  49547. case WebInspector.DockController.State.DockedToRight:
  49548. button.title = WebInspector.UIString("Dock to main window.");
  49549. button.state = "right";
  49550. break;
  49551. case WebInspector.DockController.State.Undocked: 
  49552. button.title = WebInspector.UIString("Undock into separate window.");
  49553. button.state = "undock";
  49554. break;
  49555. }
  49556. },
  49557.  
  49558. _createDockOptions: function()
  49559. {
  49560. return [this._dockToggleButtonOption];
  49561. },
  49562.  
  49563.  
  49564. _toggleDockState: function(e)
  49565. {
  49566. var action;
  49567. switch (e.target.state) {
  49568. case "bottom": action = "bottom"; break;
  49569. case "right": action = "right"; break;
  49570. case "undock": action = "undocked"; break;
  49571. }
  49572. InspectorFrontendHost.requestSetDockSide(action);
  49573. }
  49574. }
  49575.  
  49576.  
  49577.  
  49578.  
  49579.  
  49580.  
  49581.  
  49582. {(function () {
  49583. Preferences.useLowerCaseMenuTitlesOnWindows = true;
  49584. Preferences.sharedWorkersDebugNote = "Shared workers can be inspected in the Task Manager";
  49585. Preferences.localizeUI = false;
  49586. Preferences.applicationTitle = "Developer Tools - %s";
  49587. Preferences.exposeDisableCache = true;
  49588. Preferences.showDockToRight = true;
  49589. Preferences.exposeFileSystemInspection = true;
  49590. Preferences.experimentsEnabled = false;
  49591. })();}
  49592.  
  49593. function buildPlatformExtensionAPI(extensionInfo)
  49594. {
  49595. return "var extensionInfo = " + JSON.stringify(extensionInfo) + ";" +
  49596. "var tabId = " + WebInspector._inspectedTabId + ";" +
  49597. platformExtensionAPI.toString();
  49598. }
  49599.  
  49600. WebInspector.setInspectedTabId = function(tabId)
  49601. {
  49602. WebInspector._inspectedTabId = tabId;
  49603. }
  49604.  
  49605. WebInspector.clipboardAccessDeniedMessage = function()
  49606. {
  49607. return "You need to install a Chrome extension that grants clipboard access to Developer Tools.";
  49608. }
  49609.  
  49610.  
  49611.  
  49612.  
  49613.  
  49614. function platformExtensionAPI(coreAPI)
  49615. {
  49616. function getTabId()
  49617. {
  49618. return tabId;
  49619. }
  49620. chrome = window.chrome || {};
  49621.  
  49622.  
  49623.  
  49624. var devtools_descriptor = Object.getOwnPropertyDescriptor(chrome, "devtools");
  49625. if (!devtools_descriptor || devtools_descriptor.get)
  49626. Object.defineProperty(chrome, "devtools", { value: {}, enumerable: true });
  49627.  
  49628. chrome.devtools.inspectedWindow = {};
  49629. chrome.devtools.inspectedWindow.__defineGetter__("tabId", getTabId);
  49630. chrome.devtools.inspectedWindow.__proto__ = coreAPI.inspectedWindow;
  49631. chrome.devtools.network = coreAPI.network;
  49632. chrome.devtools.panels = coreAPI.panels;
  49633.  
  49634.  
  49635. if (extensionInfo.exposeExperimentalAPIs !== false) {
  49636. chrome.experimental = chrome.experimental || {};
  49637. chrome.experimental.devtools = chrome.experimental.devtools || {};
  49638.  
  49639. var properties = Object.getOwnPropertyNames(coreAPI);
  49640. for (var i = 0; i < properties.length; ++i) {
  49641. var descriptor = Object.getOwnPropertyDescriptor(coreAPI, properties[i]);
  49642. Object.defineProperty(chrome.experimental.devtools, properties[i], descriptor);
  49643. }
  49644. chrome.experimental.devtools.inspectedWindow = chrome.devtools.inspectedWindow;
  49645. }
  49646. if (extensionInfo.exposeWebInspectorNamespace)
  49647. window.webInspector = coreAPI;
  49648. }
  49649.  
  49650.  
  49651.  
  49652.  
  49653.  
  49654.  
  49655.  
  49656.  
  49657. if (window.domAutomationController) {
  49658.  
  49659. var ___interactiveUiTestsMode = true;
  49660.  
  49661.  
  49662. TestSuite = function()
  49663. {
  49664. this.controlTaken_ = false;
  49665. this.timerId_ = -1;
  49666. };
  49667.  
  49668.  
  49669.  
  49670. TestSuite.prototype.fail = function(message)
  49671. {
  49672. if (this.controlTaken_)
  49673. this.reportFailure_(message);
  49674. else
  49675. throw message;
  49676. };
  49677.  
  49678.  
  49679.  
  49680. TestSuite.prototype.assertEquals = function(expected, actual, opt_message)
  49681. {
  49682. if (expected !== actual) {
  49683. var message = "Expected: '" + expected + "', but was '" + actual + "'";
  49684. if (opt_message)
  49685. message = opt_message + "(" + message + ")";
  49686. this.fail(message);
  49687. }
  49688. };
  49689.  
  49690.  
  49691. TestSuite.prototype.assertTrue = function(value, opt_message)
  49692. {
  49693. this.assertEquals(true, !!value, opt_message);
  49694. };
  49695.  
  49696.  
  49697.  
  49698. TestSuite.prototype.assertContains = function(string, substring)
  49699. {
  49700. if (string.indexOf(substring) === -1)
  49701. this.fail("Expected to: '" + string + "' to contain '" + substring + "'");
  49702. };
  49703.  
  49704.  
  49705.  
  49706. TestSuite.prototype.takeControl = function()
  49707. {
  49708. this.controlTaken_ = true;
  49709.  
  49710. var self = this;
  49711. this.timerId_ = setTimeout(function() {
  49712. self.reportFailure_("Timeout exceeded: 20 sec");
  49713. }, 20000);
  49714. };
  49715.  
  49716.  
  49717.  
  49718. TestSuite.prototype.releaseControl = function()
  49719. {
  49720. if (this.timerId_ !== -1) {
  49721. clearTimeout(this.timerId_);
  49722. this.timerId_ = -1;
  49723. }
  49724. this.reportOk_();
  49725. };
  49726.  
  49727.  
  49728.  
  49729. TestSuite.prototype.reportOk_ = function()
  49730. {
  49731. window.domAutomationController.send("[OK]");
  49732. };
  49733.  
  49734.  
  49735.  
  49736. TestSuite.prototype.reportFailure_ = function(error)
  49737. {
  49738. if (this.timerId_ !== -1) {
  49739. clearTimeout(this.timerId_);
  49740. this.timerId_ = -1;
  49741. }
  49742. window.domAutomationController.send("[FAILED] " + error);
  49743. };
  49744.  
  49745.  
  49746.  
  49747. TestSuite.prototype.runTest = function(testName)
  49748. {
  49749. try {
  49750. this[testName]();
  49751. if (!this.controlTaken_)
  49752. this.reportOk_();
  49753. } catch (e) {
  49754. this.reportFailure_(e);
  49755. }
  49756. };
  49757.  
  49758.  
  49759.  
  49760. TestSuite.prototype.showPanel = function(panelName)
  49761. {
  49762.  
  49763. var toolbar = document.getElementById("toolbar");
  49764. var button = toolbar.getElementsByClassName(panelName)[0];
  49765. button.click();
  49766. this.assertEquals(WebInspector.panels[panelName], WebInspector.inspectorView.currentPanel());
  49767. };
  49768.  
  49769.  
  49770.  
  49771. TestSuite.prototype.addSniffer = function(receiver, methodName, override, opt_sticky)
  49772. {
  49773. var orig = receiver[methodName];
  49774. if (typeof orig !== "function")
  49775. this.fail("Cannot find method to override: " + methodName);
  49776. var test = this;
  49777. receiver[methodName] = function(var_args) {
  49778. try {
  49779. var result = orig.apply(this, arguments);
  49780. } finally {
  49781. if (!opt_sticky)
  49782. receiver[methodName] = orig;
  49783. }
  49784.  
  49785. try {
  49786. override.apply(this, arguments);
  49787. } catch (e) {
  49788. test.fail("Exception in overriden method '" + methodName + "': " + e);
  49789. }
  49790. return result;
  49791. };
  49792. };
  49793.  
  49794.  
  49795. TestSuite.prototype.testEnableResourcesTab = function()
  49796. {
  49797.  
  49798. }
  49799.  
  49800. TestSuite.prototype.testCompletionOnPause = function()
  49801. {
  49802.  
  49803. }
  49804.  
  49805.  
  49806.  
  49807.  
  49808.  
  49809. TestSuite.prototype.testShowScriptsTab = function()
  49810. {
  49811. this.showPanel("scripts");
  49812. var test = this;
  49813.  
  49814. this._waitUntilScriptsAreParsed(["debugger_test_page.html"],
  49815. function() {
  49816. test.releaseControl();
  49817. });
  49818.  
  49819. this.takeControl();
  49820. };
  49821.  
  49822.  
  49823.  
  49824. TestSuite.prototype.testScriptsTabIsPopulatedOnInspectedPageRefresh = function()
  49825. {
  49826. var test = this;
  49827. this.assertEquals(WebInspector.panels.elements, WebInspector.inspectorView.currentPanel(), "Elements panel should be current one.");
  49828.  
  49829. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.GlobalObjectCleared, waitUntilScriptIsParsed);
  49830.  
  49831.  
  49832. test.evaluateInConsole_("window.location.reload(true);", function(resultText) {});
  49833.  
  49834. function waitUntilScriptIsParsed()
  49835. {
  49836. WebInspector.debuggerModel.removeEventListener(WebInspector.DebuggerModel.Events.GlobalObjectCleared, waitUntilScriptIsParsed);
  49837. test.showPanel("scripts");
  49838. test._waitUntilScriptsAreParsed(["debugger_test_page.html"],
  49839. function() {
  49840. test.releaseControl();
  49841. });
  49842. }
  49843.  
  49844.  
  49845. this.takeControl();
  49846. };
  49847.  
  49848.  
  49849.  
  49850. TestSuite.prototype.testContentScriptIsPresent = function()
  49851. {
  49852. this.showPanel("scripts");
  49853. var test = this;
  49854.  
  49855. test._waitUntilScriptsAreParsed(
  49856. ["page_with_content_script.html", "simple_content_script.js"],
  49857. function() {
  49858. test.releaseControl();
  49859. });
  49860.  
  49861.  
  49862. this.takeControl();
  49863. };
  49864.  
  49865.  
  49866.  
  49867. TestSuite.prototype.testNoScriptDuplicatesOnPanelSwitch = function()
  49868. {
  49869. var test = this;
  49870.  
  49871.  
  49872.  
  49873.  
  49874. var expectedScriptsCount = 2;
  49875. var parsedScripts = [];
  49876.  
  49877. this.showPanel("scripts");
  49878.  
  49879. function switchToElementsTab() {
  49880. test.showPanel("elements");
  49881. setTimeout(switchToScriptsTab, 0);
  49882. }
  49883.  
  49884. function switchToScriptsTab() {
  49885. test.showPanel("scripts");
  49886. setTimeout(checkScriptsPanel, 0);
  49887. }
  49888.  
  49889. function checkScriptsPanel() {
  49890. test.assertTrue(test._scriptsAreParsed(["debugger_test_page.html"]), "Some scripts are missing.");
  49891. checkNoDuplicates();
  49892. test.releaseControl();
  49893. }
  49894.  
  49895. function checkNoDuplicates() {
  49896. var uiSourceCodes = test.nonAnonymousUISourceCodes_();
  49897. for (var i = 0; i < uiSourceCodes.length; i++) {
  49898. var scriptName = uiSourceCodes[i].fileName;
  49899. for (var j = i + 1; j < uiSourceCodes.length; j++)
  49900. test.assertTrue(scriptName !== uiSourceCodes[j].fileName, "Found script duplicates: " + test.uiSourceCodesToString_(uiSourceCodes));
  49901. }
  49902. }
  49903.  
  49904. test._waitUntilScriptsAreParsed(
  49905. ["debugger_test_page.html"],
  49906. function() {
  49907. checkNoDuplicates();
  49908. setTimeout(switchToElementsTab, 0);
  49909. });
  49910.  
  49911.  
  49912.  
  49913. this.takeControl();
  49914. };
  49915.  
  49916.  
  49917.  
  49918.  
  49919. TestSuite.prototype.testPauseWhenLoadingDevTools = function()
  49920. {
  49921. this.showPanel("scripts");
  49922.  
  49923.  
  49924. if (WebInspector.debuggerModel.debuggerPausedDetails)
  49925. return;
  49926.  
  49927. this._waitForScriptPause(this.releaseControl.bind(this));
  49928. this.takeControl();
  49929. };
  49930.  
  49931.  
  49932.  
  49933.  
  49934. TestSuite.prototype.testPauseWhenScriptIsRunning = function()
  49935. {
  49936. this.showPanel("scripts");
  49937.  
  49938. this.evaluateInConsole_(
  49939. 'setTimeout("handleClick()" , 0)',
  49940. didEvaluateInConsole.bind(this));
  49941.  
  49942. function didEvaluateInConsole(resultText) {
  49943. this.assertTrue(!isNaN(resultText), "Failed to get timer id: " + resultText);
  49944.  
  49945.  
  49946. setTimeout(testScriptPause.bind(this), 300);
  49947. }
  49948.  
  49949. function testScriptPause() {
  49950.  
  49951.  
  49952. WebInspector.panels.scripts.pauseButton.click();
  49953.  
  49954. this._waitForScriptPause(this.releaseControl.bind(this));
  49955. }
  49956.  
  49957. this.takeControl();
  49958. };
  49959.  
  49960.  
  49961.  
  49962. TestSuite.prototype.testNetworkSize = function()
  49963. {
  49964. var test = this;
  49965.  
  49966. function finishResource(resource, finishTime)
  49967. {
  49968. test.assertEquals(219, resource.transferSize, "Incorrect total encoded data length");
  49969. test.assertEquals(25, resource.resourceSize, "Incorrect total data length");
  49970. test.releaseControl();
  49971. }
  49972.  
  49973. this.addSniffer(WebInspector.NetworkDispatcher.prototype, "_finishNetworkRequest", finishResource);
  49974.  
  49975.  
  49976. test.evaluateInConsole_("window.location.reload(true);", function(resultText) {});
  49977.  
  49978. this.takeControl();
  49979. };
  49980.  
  49981.  
  49982.  
  49983. TestSuite.prototype.testNetworkSyncSize = function()
  49984. {
  49985. var test = this;
  49986.  
  49987. function finishResource(resource, finishTime)
  49988. {
  49989. test.assertEquals(219, resource.transferSize, "Incorrect total encoded data length");
  49990. test.assertEquals(25, resource.resourceSize, "Incorrect total data length");
  49991. test.releaseControl();
  49992. }
  49993.  
  49994. this.addSniffer(WebInspector.NetworkDispatcher.prototype, "_finishNetworkRequest", finishResource);
  49995.  
  49996.  
  49997. test.evaluateInConsole_("var xhr = new XMLHttpRequest(); xhr.open(\"GET\", \"chunked\", false); xhr.send(null);", function() {});
  49998.  
  49999. this.takeControl();
  50000. };
  50001.  
  50002.  
  50003.  
  50004. TestSuite.prototype.testNetworkRawHeadersText = function()
  50005. {
  50006. var test = this;
  50007.  
  50008. function finishResource(resource, finishTime)
  50009. {
  50010. if (!resource.responseHeadersText)
  50011. test.fail("Failure: resource does not have response headers text");
  50012. test.assertEquals(164, resource.responseHeadersText.length, "Incorrect response headers text length");
  50013. test.releaseControl();
  50014. }
  50015.  
  50016. this.addSniffer(WebInspector.NetworkDispatcher.prototype, "_finishNetworkRequest", finishResource);
  50017.  
  50018.  
  50019. test.evaluateInConsole_("window.location.reload(true);", function(resultText) {});
  50020.  
  50021. this.takeControl();
  50022. };
  50023.  
  50024.  
  50025.  
  50026. TestSuite.prototype.testNetworkTiming = function()
  50027. {
  50028. var test = this;
  50029.  
  50030. function finishResource(resource, finishTime)
  50031. {
  50032.  
  50033.  
  50034.  
  50035. test.assertTrue(resource.timing.receiveHeadersEnd - resource.timing.connectStart >= 70, 
  50036. "Time between receiveHeadersEnd and connectStart should be >=70ms, but was " +
  50037. "receiveHeadersEnd=" + resource.timing.receiveHeadersEnd + ", connectStart=" + resource.timing.connectStart + ".");
  50038. test.assertTrue(resource.responseReceivedTime - resource.startTime >= 0.07, 
  50039. "Time between responseReceivedTime and startTime should be >=0.07s, but was " +
  50040. "responseReceivedTime=" + resource.responseReceivedTime + ", startTime=" + resource.startTime + ".");
  50041. test.assertTrue(resource.endTime - resource.startTime >= 0.14, 
  50042. "Time between endTime and startTime should be >=0.14s, but was " +
  50043. "endtime=" + resource.endTime + ", startTime=" + resource.startTime + ".");
  50044.  
  50045. test.releaseControl();
  50046. }
  50047.  
  50048. this.addSniffer(WebInspector.NetworkDispatcher.prototype, "_finishNetworkRequest", finishResource);
  50049.  
  50050.  
  50051. test.evaluateInConsole_("window.location.reload(true);", function(resultText) {});
  50052.  
  50053. this.takeControl();
  50054. };
  50055.  
  50056.  
  50057. TestSuite.prototype.testConsoleOnNavigateBack = function()
  50058. {
  50059. if (WebInspector.console.messages.length === 1)
  50060. firstConsoleMessageReceived.call(this);
  50061. else
  50062. WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, firstConsoleMessageReceived, this);
  50063.  
  50064. function firstConsoleMessageReceived() {
  50065. this.evaluateInConsole_("clickLink();", didClickLink.bind(this));
  50066. }
  50067.  
  50068. function didClickLink() {
  50069.  
  50070. this.assertEquals(1, WebInspector.console.messages.length);
  50071. this.assertEquals(1, WebInspector.console.messages[0].totalRepeatCount);
  50072. this.evaluateInConsole_("history.back();", didNavigateBack.bind(this));
  50073. }
  50074.  
  50075. function didNavigateBack()
  50076. {
  50077.  
  50078. this.evaluateInConsole_("void 0;", didCompleteNavigation.bind(this));
  50079. }
  50080.  
  50081. function didCompleteNavigation() {
  50082. this.assertEquals(1, WebInspector.console.messages.length);
  50083. this.assertEquals(1, WebInspector.console.messages[0].totalRepeatCount);
  50084. this.releaseControl();
  50085. }
  50086.  
  50087. this.takeControl();
  50088. };
  50089.  
  50090.  
  50091. TestSuite.prototype.testReattachAfterCrash = function()
  50092. {
  50093. this.evaluateInConsole_("1+1;", this.releaseControl.bind(this));
  50094. this.takeControl();
  50095. };
  50096.  
  50097.  
  50098. TestSuite.prototype.testSharedWorker = function()
  50099. {
  50100. function didEvaluateInConsole(resultText) {
  50101. this.assertEquals("2011", resultText);
  50102. this.releaseControl();
  50103. }
  50104. this.evaluateInConsole_("globalVar", didEvaluateInConsole.bind(this));
  50105. this.takeControl();
  50106. };
  50107.  
  50108.  
  50109. TestSuite.prototype.testPauseInSharedWorkerInitialization = function()
  50110. {
  50111. if (WebInspector.debuggerModel.debuggerPausedDetails)
  50112. return;
  50113. this._waitForScriptPause(this.releaseControl.bind(this));
  50114. this.takeControl();
  50115. };
  50116.  
  50117.  
  50118.  
  50119. TestSuite.prototype.testPageOverlayUpdate = function()
  50120. {
  50121. var test = this;
  50122. var records = [];
  50123. var dispatchOnRecordType = {}
  50124.  
  50125. function addRecord(event)
  50126. {
  50127. innerAddRecord(event.data);
  50128. }
  50129.  
  50130. function innerAddRecord(record)
  50131. {
  50132. records.push(record);
  50133. if (typeof dispatchOnRecordType[record.type] === "function")
  50134. dispatchOnRecordType[record.type](record);
  50135.  
  50136. if (record.children)
  50137. record.children.forEach(innerAddRecord);
  50138. }
  50139.  
  50140. function populatePage()
  50141. {
  50142. var div1 = document.createElement("div");
  50143. div1.id = "div1";
  50144.  
  50145. div1.style.webkitTransform = "translateZ(0)";
  50146. document.body.appendChild(div1);
  50147. var div2 = document.createElement("div");
  50148. div2.id = "div2";
  50149. document.body.appendChild(div2);
  50150. }
  50151.  
  50152. function step1()
  50153. {
  50154. WebInspector.timelineManager.addEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, addRecord);
  50155. WebInspector.timelineManager.start();
  50156.  
  50157. test.evaluateInConsole_(populatePage.toString() + "; populatePage();" +
  50158. "inspect(document.getElementById('div1'))", function() {});
  50159. WebInspector.notifications.addEventListener(WebInspector.ElementsTreeOutline.Events.SelectedNodeChanged, step2);
  50160. }
  50161.  
  50162. function step2()
  50163. {
  50164. WebInspector.notifications.removeEventListener(WebInspector.ElementsTreeOutline.Events.SelectedNodeChanged, step2);
  50165. setTimeout(step3, 500);
  50166. }
  50167.  
  50168. function step3()
  50169. {
  50170. test.evaluateInConsole_("inspect(document.getElementById('div2'))", function() {});
  50171. WebInspector.notifications.addEventListener(WebInspector.ElementsTreeOutline.Events.SelectedNodeChanged, step4);
  50172. }
  50173.  
  50174. function step4()
  50175. {
  50176. WebInspector.notifications.removeEventListener(WebInspector.ElementsTreeOutline.Events.SelectedNodeChanged, step4);
  50177. dispatchOnRecordType.TimeStamp = step5;
  50178. test.evaluateInConsole_("console.timeStamp('ready')", function() {});
  50179. }
  50180.  
  50181. function step5()
  50182. {
  50183. var types = {};
  50184. WebInspector.timelineManager.stop();
  50185. WebInspector.timelineManager.removeEventListener(WebInspector.TimelineManager.EventTypes.TimelineEventRecorded, addRecord);
  50186. for (var i = 0; i < records.length; ++i)
  50187. types[records[i].type] = (types[records[i].type] || 0) + 1;
  50188.  
  50189. var frameCount = types["BeginFrame"];
  50190.  
  50191. test.assertTrue(frameCount >= 2, "Not enough DevTools overlay updates");
  50192.  
  50193.  
  50194. test.assertTrue(frameCount < 6, "Too many updates caused by DevTools overlay");
  50195. test.releaseControl();
  50196. }
  50197.  
  50198. step1();
  50199. this.takeControl();
  50200. }
  50201.  
  50202. TestSuite.prototype.waitForTestResultsInConsole = function()
  50203. {
  50204. var messages = WebInspector.console.messages;
  50205. for (var i = 0; i < messages.length; ++i) {
  50206. var text = messages[i].text;
  50207. if (text === "PASS")
  50208. return;
  50209. else if (/^FAIL/.test(text))
  50210. this.fail(text); 
  50211. }
  50212.  
  50213. function onConsoleMessage(event)
  50214. {
  50215. var text = event.data.text;
  50216. if (text === "PASS")
  50217. this.releaseControl();
  50218. else if (/^FAIL/.test(text))
  50219. this.fail(text);
  50220. }
  50221.  
  50222. WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, onConsoleMessage, this);
  50223. this.takeControl();
  50224. };
  50225.  
  50226. TestSuite.prototype.checkLogAndErrorMessages = function()
  50227. {
  50228. var messages = WebInspector.console.messages;
  50229.  
  50230. var matchesCount = 0;
  50231. function validMessage(message)
  50232. {
  50233. if (message.text === "log" && message.level === WebInspector.ConsoleMessage.MessageLevel.Log) {
  50234. ++matchesCount;
  50235. return true;
  50236. }
  50237.  
  50238. if (message.text === "error" && message.level === WebInspector.ConsoleMessage.MessageLevel.Error) {
  50239. ++matchesCount;
  50240. return true;
  50241. }
  50242. return false;
  50243. }
  50244.  
  50245. for (var i = 0; i < messages.length; ++i) {
  50246. if (validMessage(messages[i]))
  50247. continue;
  50248. this.fail(messages[i].text + ":" + messages[i].level); 
  50249. }
  50250.  
  50251. if (matchesCount === 2)
  50252. return;
  50253.  
  50254.  
  50255. function onConsoleMessage(event)
  50256. {
  50257. var message = event.data;
  50258. if (validMessage(message)) {
  50259. if (matchesCount === 2) {
  50260. this.releaseControl();
  50261. return;
  50262. }
  50263. } else
  50264. this.fail(message.text + ":" + messages[i].level);
  50265. }
  50266.  
  50267. WebInspector.console.addEventListener(WebInspector.ConsoleModel.Events.MessageAdded, onConsoleMessage, this);
  50268. this.takeControl();
  50269. };
  50270.  
  50271.  
  50272. TestSuite.prototype.uiSourceCodesToString_ = function(uiSourceCodes)
  50273. {
  50274. var names = [];
  50275. for (var i = 0; i < uiSourceCodes.length; i++)
  50276. names.push('"' + uiSourceCodes[i].fileName + '"');
  50277. return names.join(",");
  50278. };
  50279.  
  50280.  
  50281.  
  50282. TestSuite.prototype.nonAnonymousUISourceCodes_ = function()
  50283. {
  50284. function filterOutAnonymous(uiSourceCode)
  50285. {
  50286. return !!uiSourceCode.url;
  50287. }
  50288.  
  50289. var uiSourceCodes = WebInspector.workspace.uiSourceCodes();
  50290. return uiSourceCodes.filter(filterOutAnonymous);
  50291. };
  50292.  
  50293.  
  50294.  
  50295. TestSuite.prototype.evaluateInConsole_ = function(code, callback)
  50296. {
  50297. WebInspector.showConsole();
  50298. WebInspector.consoleView.prompt.text = code;
  50299. WebInspector.consoleView.promptElement.dispatchEvent(TestSuite.createKeyEvent("Enter"));
  50300.  
  50301. this.addSniffer(WebInspector.ConsoleView.prototype, "_appendConsoleMessage",
  50302. function(commandResult) {
  50303. callback(commandResult.toMessageElement().textContent);
  50304. });
  50305. };
  50306.  
  50307.  
  50308.  
  50309. TestSuite.prototype._scriptsAreParsed = function(expected)
  50310. {
  50311. var uiSourceCodes = this.nonAnonymousUISourceCodes_();
  50312.  
  50313. var missing = expected.slice(0);
  50314. for (var i = 0; i < uiSourceCodes.length; ++i) {
  50315. for (var j = 0; j < missing.length; ++j) {
  50316. if (uiSourceCodes[i].parsedURL.lastPathComponent.search(missing[j]) !== -1) {
  50317. missing.splice(j, 1);
  50318. break;
  50319. }
  50320. }
  50321. }
  50322. return missing.length === 0;
  50323. };
  50324.  
  50325.  
  50326.  
  50327. TestSuite.prototype._waitForScriptPause = function(callback)
  50328. {
  50329. function pauseListener(event) {
  50330. WebInspector.debuggerModel.removeEventListener(WebInspector.DebuggerModel.Events.DebuggerPaused, pauseListener, this);
  50331. callback();
  50332. }
  50333. WebInspector.debuggerModel.addEventListener(WebInspector.DebuggerModel.Events.DebuggerPaused, pauseListener, this);
  50334. };
  50335.  
  50336.  
  50337.  
  50338. TestSuite.prototype._executeCodeWhenScriptsAreParsed = function(code, expectedScripts)
  50339. {
  50340. var test = this;
  50341.  
  50342. function executeFunctionInInspectedPage() {
  50343.  
  50344.  
  50345. test.evaluateInConsole_(
  50346. 'setTimeout("' + code + '" , 0)',
  50347. function(resultText) {
  50348. test.assertTrue(!isNaN(resultText), "Failed to get timer id: " + resultText + ". Code: " + code);
  50349. });
  50350. }
  50351.  
  50352. test._waitUntilScriptsAreParsed(expectedScripts, executeFunctionInInspectedPage);
  50353. };
  50354.  
  50355.  
  50356.  
  50357. TestSuite.prototype._waitUntilScriptsAreParsed = function(expectedScripts, callback)
  50358. {
  50359. var test = this;
  50360.  
  50361. function waitForAllScripts() {
  50362. if (test._scriptsAreParsed(expectedScripts))
  50363. callback();
  50364. else
  50365. test.addSniffer(WebInspector.panels.scripts, "_addUISourceCode", waitForAllScripts);
  50366. }
  50367.  
  50368. waitForAllScripts();
  50369. };
  50370.  
  50371.  
  50372.  
  50373. TestSuite.createKeyEvent = function(keyIdentifier)
  50374. {
  50375. var evt = document.createEvent("KeyboardEvent");
  50376. evt.initKeyboardEvent("keydown", true  , true  , null  , keyIdentifier, "");
  50377. return evt;
  50378. };
  50379.  
  50380.  
  50381.  
  50382. var uiTests = {};
  50383.  
  50384.  
  50385.  
  50386. uiTests.runAllTests = function()
  50387. {
  50388.  
  50389. for (var name in TestSuite.prototype) {
  50390. if (name.substring(0, 4) === "test" && typeof TestSuite.prototype[name] === "function")
  50391. uiTests.runTest(name);
  50392. }
  50393. };
  50394.  
  50395.  
  50396.  
  50397. uiTests.runTest = function(name)
  50398. {
  50399. if (uiTests._populatedInterface)
  50400. new TestSuite().runTest(name);
  50401. else
  50402. uiTests._pendingTestName = name;
  50403. };
  50404.  
  50405. (function() {
  50406.  
  50407. function runTests()
  50408. {
  50409. uiTests._populatedInterface = true;
  50410. var name = uiTests._pendingTestName;
  50411. delete uiTests._pendingTestName;
  50412. if (name)
  50413. new TestSuite().runTest(name);
  50414. }
  50415.  
  50416. var oldLoadCompleted = InspectorFrontendAPI.loadCompleted;
  50417. InspectorFrontendAPI.loadCompleted = function()
  50418. {
  50419. oldLoadCompleted.call(InspectorFrontendAPI);
  50420. runTests();
  50421. }
  50422.  
  50423. })();
  50424.  
  50425. }
  50426.  
  50427.